Issue
When I want a user directory as a normal user in Python3, from terminal
>>> os.path.expanduser('~')
/home/user
When I run in the root (sudo su
)
>>> os.path.expanduser('~')
/root/
Is there any way to get the /home/user directory from the root user in python3?
Solution
os.path.expanduser('~{user}')
Where {user} is any user, in your case...user:
os.path.expanduser('~user')
Answered By - Bret Hogg