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:
However, this does not work on Windows. What is the correct cross-platform way to do this?
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())
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(2018, 25, ...READ MORE
You can also use the random library's ...READ MORE
colors = ['red', 'green', ...READ MORE
Enumerate() method adds a counter to an ...READ MORE
You can simply the built-in function in ...READ MORE
would suggest using glob.iglob() instead of the glob.glob(), as ...READ MORE
The easiest way is to use shutil.make_archive. ...READ MORE
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.