Getting Home Directory with pathlib

Alex Bliskovsky picture Alex Bliskovsky · Apr 8, 2014 · Viewed 11k times · Source

Looking through the new pathlib module in Python 3.4, I notice that there isn't any simple way to get the user's home directory. The only way I can come up with for getting a user's home directory is to use the older os.path lib like so:

import pathlib
from os import path
p = pathlib.Path(path.expanduser("~"))

This seems clunky. Is there a better way?

Answer

simon picture simon · Oct 20, 2015

As of python-3.5, there is Path.home(), which improves the situation somewhat.