- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the home directory in Python?
To get the homedir in python, you can use os.path.expanduser('~') from the os module. This also works if its a part of a longer path like ~/Documents/my_folder/. If there is no ~ in the path, the function will return the path unchanged. You can use it like −
import os print(os.path.expanduser('~'))
You can also query the environment variables for the HOME variable −
import os print(os.environ['HOME'])
- Get Java Home Directory
- How to find the real user home directory using Python?
- How do I get the parent directory in Python?
- How to get the current username and directory in Golang?
- How to get root directory information in android?
- Get the Current Working Directory in Java
- How to get a list of all sub-directories in the current directory using Python?
- How to set the current working directory in Python?
- Java Program to get the name of the parent directory of the file or directory
- How to get system data directory information in android?
- How to get full path of current file's directory in Python?
- Fiber To The Home
- How to rename directory using Python?
- How to get the names of the empty directories in a directory in Java?
- C# Program to get the name of root directory