Forum Archive

Missing pathlib.expanduser()?

mikael

With this:

import pathlib
p = pathlib.Path('~/Documents')
p.expanduser()

... I get a stacktrace:

AttributeError: 'PosixPath' object has no attribute 'expanduser'

dir(p) shows no trace of expanduser, although it should have been there since 3.5.

Any ideas why? Something I am doing or A Pythonista quirk?

cvp

@mikael no error for me....try restart Pythonista

mikael

@cvp, thanks!

It was a classic case of something having pulled an old version of pathlib.py to site-packages.

Easy to find by checking pathlib.__file__.

Deleted & restarted & solved.

cvp

@mikael just wanted to say

print(os.path.dirname(pathlib.__file__)) 
mikael

@cvp, I am confused about the added value?

>>> import pathlib
>>> pathlib.__file__
'/var/containers/Bundle/Application/B21D36A1-33F6-45D3-8E39-FFD13E200E5D/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/pathlib.py'
>>> import os.path
>>> os.path.dirname(pathlib.__file__)
'/var/containers/Bundle/Application/B21D36A1-33F6-45D3-8E39-FFD13E200E5D/Pythonista3.app/Frameworks/Py3Kit.framework/pylib'
cvp

@mikael Not a big added value 😀 It shows it is part of Pythonista but if you get a folder like site-packages, it proves you have an unwanted copy