Use os.path.expanduser(path)
, see http://docs.python.org/library/os.path.html
e.g. expanduser('~/filename')
This works on both Unix and Windows, according to the docs.
Edit: forward slash due to Sven’s comment.
More Related Contents:
- Randomly generate 4 or 5 digit Unique Codes in Subsequent Runs of the Script
- Why is it string.join(list) instead of list.join(string)?
- Does Python have an ordered set?
- Why does list.append evaluate to false in a boolean context? [duplicate]
- How to initialize a two-dimensional array in Python?
- Rank items in an array using Python/NumPy, without sorting array twice
- Execution of Python code with -m option or not
- Split a string at uppercase letters
- Selenium waitForElement
- Cannot find vcvarsall.bat when running a Python script
- Set up Python on Windows to not type “python” in cmd
- Scrapy Very Basic Example
- Changing image hue with Python PIL
- Good uses for mutable function argument default values?
- Tensorflow, best way to save state in RNNs?
- Remove ‘b’ character do in front of a string literal in Python 3 [duplicate]
- pydot and graphviz error: Couldn’t import dot_parser, loading of dot files will not be possible
- Python Encrypting with PyCrypto AES
- Compact way to assign values by slicing list in Python
- how to test if one python module has been imported?
- python pandas read_csv delimiter in column data
- Python import modules from a higher level package
- I have a string whose content is a function name, how to refer to the corresponding function in Python?
- How can I safely create a directory (possibly including intermediate directories)?
- Automatically run %matplotlib inline in IPython Notebook
- Python ConfigParser cannot search .ini file correctly (Ubuntu 14, Python 3.4)
- Error: No module named ‘fcntl’
- How to CREATE a transparent gif (or png) with PIL (python-imaging)
- How to pass flag to gcc in Python setup.py script?
- Python: Random numbers into a list