is pathlib Path.resolve working as intended?

Chris Cioffi chris at evenprimes.com
Tue Dec 23 13:53:13 EST 2014


Ok, I'm guessing I'm doing something wrong, but I can't see what.

I'm playing around with pathlib (Python 3.4.2) on Mac OSX, Yosemite.

In the past I've used os.path.expanduser() to expand paths with ~.  Based on the description, I would have expected .resolve to do that automatically, but it doesn't seem to work.

Is this a bug, oversight or design choice?

Here's my example of what I was doing:

>>> p = Path('~/.profile')
>>> p
PosixPath('~/.profile')
>>> p.resolve
<bound method PosixPath.resolve of PosixPath('~/.profile')>
>>> 
>>> p.resolve()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/pathlib.py", line 1031, in resolve
    s = self._flavour.resolve(self)
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/pathlib.py", line 297, in resolve
    return _resolve(base, str(path)) or sep
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/pathlib.py", line 282, in _resolve
    target = accessor.readlink(newpath)
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/pathlib.py", line 374, in readlink
    return os.readlink(path)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/chris/~'
>>> 


Chris


More information about the Python-list mailing list