This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pathlib.Path on Windows - parser issue
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, paul.moore, steve.dower, tempest, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2019-11-27 17:15 by tempest, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg357574 - (view) Author: (tempest) Date: 2019-11-27 17:15
the Path parser from pathlib seems to give incorrect paths if a folder (subdirectory) name includes a period. (This issue does not manifest with Unix paths.) 

Please see a demonstration below: "Out[2]" is not the same as "Out[3]" and "Out[4]"; the "\" separator following the folder name with the period is not converted to the forward slash ("/") in the WindowsPath() when the full path is given as a Windows path string. This issue manifests with pathlib.WindowsPath() as well. This is Python 3.7.4 from the Anaconda distribution.

Jupyter QtConsole 4.6.0
Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from pathlib import Path

In [2]: Path('C:\Temp\MyProj.wc\test.eps')
Out[2]: WindowsPath('C:/Temp/MyProj.wc\test.eps')

In [3]: Path('C:\Temp\MyProj.wc').joinpath('test.eps')
Out[3]: WindowsPath('C:/Temp/MyProj.wc/test.eps')

In [4]: Path('C:/Temp/MyProj.wc/test.eps')
Out[4]: WindowsPath('C:/Temp/MyProj.wc/test.eps')
msg357577 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2019-11-27 18:00
Note that you're using backslashes in a non-raw string; in particular, you're naming your file `\x09est.eps`.  Try `Path(r'C:\Temp\MyProj.wc\test.eps')` and see if that works for you.
msg357616 - (view) Author: (tempest) Date: 2019-11-28 13:19
But for course! (Slaps forehead!)

Yes, giving the Windows path as a raw string works. For all the times I've done '\t'.join(str(f) for f in some_array) to get a tab-delimited text string, I should have had a clue. Sorry for the noise, and thanks for setting me straight.
msg357619 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2019-11-28 15:48
You're welcome :)
History
Date User Action Args
2022-04-11 14:59:23adminsetgithub: 83112
2019-11-28 15:48:13zach.waresetstatus: open -> closed
resolution: not a bug
messages: + msg357619

stage: resolved
2019-11-28 13:19:25tempestsetmessages: + msg357616
2019-11-27 18:00:04zach.waresetmessages: + msg357577
2019-11-27 17:31:38brett.cannonsetnosy: + brett.cannon
2019-11-27 17:16:00tempestcreate