94232/how-to-get-the-home-directory-in-python
I need to get the location of the home directory of the current logged-on user. Currently, I've been using the following on Linux:
os.getenv("HOME")
However, this does not work on Windows. What is the correct cross-platform way to do this?
Hello,
You need 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())
Hello, @Roshni, You need to import the os module, ...READ MORE
If you are talking about the length ...READ MORE
FOLLOWING WAY TO FIND CURRENT TIME IN ...READ MORE
>>> import datetime >>> datetime.datetime.now() datetime(2018, 25, ...READ MORE
You can also use the random library's ...READ MORE
Syntax : list. count(value) Code: colors = ['red', 'green', ...READ MORE
Enumerate() method adds a counter to an ...READ MORE
You can simply the built-in function in ...READ MORE
Hello @kartik, would suggest using glob.iglob() instead of the glob.glob(), as ...READ MORE
Hello @kartik, The easiest way is to use shutil.make_archive. ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.