You want to use os.path.expanduser.
This will ensure it works on all platforms:
from os.path import expanduser
home = expanduser("~")
If you’re on Python 3.5+ you can use pathlib.Path.home():
from pathlib import Path
home = str(Path.home())
More Related Contents:
- What is the correct cross-platform way to get the home directory in Python?
- How do you run a Python script as a service in Windows?
- Python: What OS am I running on?
- Monitoring contents of files/directories? [duplicate]
- Python: Platform independent way to modify PATH environment variable
- How to find the real user home directory using python?
- How to identify on which OS Python is running on?
- How to share conda environments across platforms
- How can I find the current OS in Python? [duplicate]
- Possible values from sys.platform?
- Cross-platform subprocess with hidden window
- How to add a timeout to a function in Python
- Regular Expression to match cross platform newline characters
- How can I create a ramdisk in Python?
- How to identify which OS Python is running on?
- Platform-independent file paths?
- Why does the calculated width and height in pixel of a string in Tkinter differ between platforms?
- Cross-platform way to get PIDs by process name in python
- Cross-platform gui toolkit for deploying Python applications
- Python multiprocessing linux windows difference
- How to draw a histogram from existing bin values
- How can I do a line break (line continuation) in Python?
- Is there a zip-like function that pads to longest length?
- ‘str’ object has no attribute ‘decode’. Python 3 error?
- Selenium Webdriver: How to Download a PDF File with Python?
- Python – DM a User Discord Bot
- how to pass parameters of a function when using timeit.Timer()
- Django widget override template
- When using cx_Freeze and tkinter I get: “DLL load failed: The specified module could not be found.” (Python 3.5.3)
- When should I use root.update() in tkInter for python