Categories
Python Answers

How to get the home directory in Python?

Spread the love

Sometimes, we want to get the home directory in Python.

In this article, we’ll look at how to get the home directory in Python.

How to get the home directory in Python?

To get the home directory in Python, we can use the Path module.

For instance, we write

from pathlib import Path

home = str(Path.home())

to call Path.home method to return the home directory as a path object.

We then convert it to a string with str.

Conclusion

To get the home directory in Python, we can use the Path module.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *