You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ntpath not adding slash after drive letters #124167
In my previous PR #122372
I found that ntpath and nturl2path are not documented. In the comment of nturl2path, it is mentioned that it is only used by urllib, but it is not in the urllib folder and is not a private module with an _ prefix (like _colorize), so we can import and use it freely.
Searching for "import nturl2path" on GitHub also shows that a considerable number of people use it. I am curious why these two modules do not have documentation, is it a historical legacy issue?
They are not restricted by the system, but the functions they provide are Windows-specific file paths. Should we add their documentation? Or keep it that way
I want to answer this question, but I don't know if it's a feature or a bug, so we have to read the source code
In CommandPrompt, cd C:Users fails. If same is true of os.chdir('C:Users'), then this seems a bug.
EDIT: The above is not quite right as cd e:Languages worked in the sense that when I switched to the e drive, Languages had become the working directory there. But c:xxx seems 'Not found' even when 'xxx' exists.
If a file name begins with only a disk designator but not the backslash after the colon, it is interpreted as a relative path to the current directory on the drive with the specified letter. Note that the current directory may or may not be the root directory depending on what it was set to during the most recent "change directory" operation on that disk. Examples of this format are as follows:
"C:tmp.txt" refers to a file named "tmp.txt" in the current directory on drive C.
"C:tempdir\tmp.txt" refers to a file in a subdirectory to the current directory on drive C.
This is not a bug, it's an oddity of Windows file paths. On POSIX-ish platforms, there are relative (some/path/rooted/in/cwd/example.py) and absolute (/some/path/rooted/at/the/root/example.py) paths. On Windows each drive has its own current working directory (cwd), so there are relative (some\path\rooted\in\cwd\example.py), absolute (C:\some\path\on\drive_c\rooted\in\drive_c_root\example.py), drive-relative1 (C:some\path\on\drive_c\rooted\in\drive_c_cwd\example.py), and drive-agnostic-absolute1 (\some\path\on\current\drive\at\its\root\example.py). ntpath can't guess what kind you actually want, so if you want a rooted path you need to provide the root in addition to the drive.
Activity
Wulian233 commentedon Sep 17, 2024
In my previous PR
#122372
I found that
ntpathandnturl2pathare not documented. In the comment of nturl2path, it is mentioned that it is only used by urllib, but it is not in the urllib folder and is not a private module with an_prefix (like _colorize), so we can import and use it freely.https://github.com/python/cpython/blob/main/Lib/nturl2path.py
Searching for "import nturl2path" on GitHub also shows that a considerable number of people use it. I am curious why these two modules do not have documentation, is it a historical legacy issue?
Discussion #120423
They are not restricted by the system, but the functions they provide are Windows-specific file paths. Should we add their documentation? Or keep it that way
I want to answer this question, but I don't know if it's a feature or a bug, so we have to read the source code
https://github.com/python/cpython/blob/main/Lib/ntpath.py
Wulian233 commentedon Sep 17, 2024
oh, ntpath is a part of os.path
https://github.com/python/cpython/blob/main/Doc%2Flibrary%2Fos.path.rst#L7-L8
matan1008 commentedon Sep 17, 2024
I actually found the issue using pathlib, so I guess it is a serious API change. I have a PR ready to be pushed, if it is something you would like 😀
terryjreedy commentedon Sep 17, 2024
In CommandPrompt,
cd C:Usersfails. If same is true ofos.chdir('C:Users'), then this seems a bug.EDIT: The above is not quite right as
cd e:Languagesworked in the sense that when I switched to the e drive, Languages had become the working directory there. Butc:xxxseems 'Not found' even when 'xxx' exists.barneygale commentedon Sep 17, 2024
https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file says:
zware commentedon Sep 17, 2024
This is not a bug, it's an oddity of Windows file paths. On POSIX-ish platforms, there are relative (
some/path/rooted/in/cwd/example.py) and absolute (/some/path/rooted/at/the/root/example.py) paths. On Windows each drive has its own current working directory (cwd), so there are relative (some\path\rooted\in\cwd\example.py), absolute (C:\some\path\on\drive_c\rooted\in\drive_c_root\example.py), drive-relative1 (C:some\path\on\drive_c\rooted\in\drive_c_cwd\example.py), and drive-agnostic-absolute1 (\some\path\on\current\drive\at\its\root\example.py).ntpathcan't guess what kind you actually want, so if you want a rooted path you need to provide the root in addition to the drive.Footnotes
Not sure what the real names should be ↩ ↩2
matan1008 commentedon Sep 18, 2024
So in the above example (or in pathlib) what is the correct way to get
PureWindowsPath('c:/x/y')?PureWindowsPath('c:') / '\\x' / 'y'?zware commentedon Sep 18, 2024
That would be fine, as would
PureWindowsPath('c:\\') / 'x' / 'y'orPureWindowsPath('c:') / '/' / 'x' / 'y'