What is the correct cross-platform way 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 ?

4 s
4

Leave a Comment