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())
Related Posts:
- How to use filter, map, and reduce in Python 3
- What does enumerate() mean?
- Does Python have a ternary conditional operator?
- What is the difference between Python’s list methods append and extend?
- Iterating over dictionaries using ‘for’ loops
- how to sort pandas dataframe from one column
- Understanding slice notation
- How do I sort a dictionary by value?
- How do I sort a dictionary by value?
- How to iterate over rows in a DataFrame in Pandas
- How to convert list to string [duplicate]
- How to uninstall a package installed with pip install –user
- numpy max vs amax vs maximum
- TypeError: ‘str’ object is not callable (Python)
- Save plot to image file instead of displaying it using Matplotlib
- ModuleNotFoundError: No module named ‘sklearn’
- Does Python have an ordered set?
- Asking the user for input until they give a valid response
- Print a list in reverse order with range()?
- Configuring so that pip install can work from github
- Proper way to declare custom exceptions in modern Python?
- TypeError: ‘float’ object not iterable
- write() versus writelines() and concatenated strings
- Why is it string.join(list) instead of list.join(string)?
- Importing class from another file [duplicate]
- Pandas group-by and sum
- Tkinter understanding mainloop
- How can I get a list shape without using numpy?
- AttributeError: ‘str’ object has no attribute ‘append’
- python socket.error: [Errno 98] Address already in use
- How to read a .xlsx file using the pandas Library in iPython?
- Numpy/Python Array Value error
- Changing the “tick frequency” on x or y axis in matplotlib?
- TypeError: unsupported operand type(s) for -: ‘str’ and ‘str’
- Remove all special characters, punctuation and spaces from string
- AttributeError: ” object has no attribute ”
- Plot pie chart and table of pandas dataframe
- ModuleNotFoundError: No module named ‘matplotlib’
- “inconsistent use of tabs and spaces in indentation”
- Pandas ‘count(distinct)’ equivalent
- How can I flush the output of the print function?
- Python calling method in class
- No module named pkg_resources
- Opening a .ipynb.txt File
- Python [Errno 98] Address already in use
- How do you call an instance of a class in Python?
- Flask ImportError: No Module Named Flask
- How do you use subprocess.check_output() in Python?
- ImportError: libcuda.so.1: cannot open shared object file
- TypeError: list indices must be integers or slices, not str
- python object() takes no parameters error
- How do I find the distance between two points?
- How do I calculate percentiles with python/numpy?
- How do I remove a substring from the end of a string?
- Selecting with complex criteria from pandas.DataFrame
- How can I download Anaconda for python 3.6
- django:django.core.exceptions.AppRegistryNotReady: Apps aren’t loaded yet
- Replace and overwrite instead of appending
- module ‘pandas’ has no attribute ‘rolling_mean’
- Pytesseract : “TesseractNotFound Error: tesseract is not installed or it’s not in your path”, how do I fix this?
- Pointers in Python?
- Django – no such table exception
- How to make a histogram from a list of data
- Using __add__ operator with multiple arguments in Python
- How to constantly run Python script in the background on Windows?
- Django – “no module named django.core.management”
- Type error Unhashable type:set
- Saving a Numpy array as an image
- What does “Symbol not found / Expected in: flat namespace” actually mean?
- Windows path in Python
- Python: ValueError: Mixing iteration and read methods would lose data
- python: restarting a loop
- “for loop” with two variables?
- Find the unique values in a column and then sort them
- How to install discord.py rewrite?
- Python: urllib.error.HTTPError: HTTP Error 404: Not Found
- Display number with leading zeros
- Running Python in PowerShell?
- Why do many examples use `fig, ax = plt.subplots()` in Matplotlib/pyplot/python
- ImportError: No module named model_selection
- Numpy – add row to array
- How to change pip installation path
- What is the difference between a string and a byte string?
- “This constructor takes no arguments” error in __init__
- CSV new-line character seen in unquoted field error
- Creating a truth table for any expression in Python
- Rolling or sliding window iterator?
- What is a namespace object?
- How to serve static files in Flask
- How to create Gephi network graphs from Python?
- strncmp in python
- How can I count time in Python 3?
- TypeError: ManyRelatedManager object is not iterable
- vectorize conditional assignment in pandas dataframe
- Using print() (the function version) in Python2.x
- Is it possible to forward-declare a function in Python?
- Python OpenCV2 (cv2) wrapper to get image size?
- KeyError: ‘plotly_domain’
- The value of _stdout is incorrect
- Import file from parent directory?