How do I find my home directory?

Asked 2 years ago, Updated 2 years ago, 131 views

I need to find the home directory path of the logged in user What I'm using on Linux is os.getenv("HOME") I can't do this on Windows. Is there a function that can use both Windows and Linux?

python cross-platform home-directory

2022-09-21 20:47

1 Answers

This feature is provided by os.path.expanduser(path).

It works on Windows and Linux You can use it as below.

from os.path import expanduser
home = expanduser("~")
#or
home = expanduser ("~Demi") #UserName


2022-09-21 20:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.