Getting Home Directory with pathlib
There is method expanduser()
:
p = PosixPath('~/films/Monty Python')
p.expanduser()
PosixPath('/home/eric/films/Monty Python')
As of python-3.5, there is pathlib.Path.home()
, which improves the situation somewhat.
The result on Windows is
>>>pathlib.Path.home()
WindowsPath('C:/Users/username')
and on Linux
>>>pathlib.Path.home()
PosixPath('/home/username')