I have the following file: ~/.config.txt
which is located in /root/.config
. In order to avoid hardcoded paths in my Python
file, how can I always replace (and correctly refer) to a ~/
path as <home>
in Python?
This way I could replace ~/.config.txt
by /root/.config
if /root/
was my home directory?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
You can use
os.path.expanduser
to convert~
into your home directory:This works on both *nix and Windows systems.