Python 3, OS, Example in Windows 10
If you are creating a program for a user where you want to store or use a file in the users home directory, it is not as easy as simply preparing a fixed file location like:
C:\Users\yagisanatode\
Because if another user on another computer tries to use your program they will start getting errors because their home directory might be something else like:
C:\Users\batman\
You can, however, get the users home directory by using Python’s os.path.expanduser
method.
1 2 3 4 5 |
>>> import os >>> home = os.path.expanduser('~') >>> home 'C:\\Users\\yagisanatode' >>> |
Continue reading “How to Check a User’s Home Directory for a Folder – Python 3”