Re:Why Does Windows Use Backslash as Path Separator?
by PaulHoule on Wednesday April 24, 2024 @06:01PM
(#40150299)
I am really in the habit of using pathlib in Python and similar facilities in Java so I just write
[ Parent
| on HN ]
Re:Why Does Windows Use Backslash as Path Separator?
by coldpie on Wednesday April 24, 2024 @06:04PM
(#40150334)
You can do, or you can just skip all the spaces and extra quotes and junk and just use literal /.
path = f"{HOME}/cards/{card_id}/card.yaml"
Easier to read & write IMO, and works fine. Even on Windows.
Re:Why Does Windows Use Backslash as Path Separator?
by skinner927 on Wednesday April 24, 2024 @06:21PM
(#40150558)
I really think they goofed Pathlib because of this.
path = Path(“/foo”) / “a” / “b” / “c”
The following is functionally equivalent to the above: path = Path(“/foo”) / “a/b/c”
Which I really think was a mistake. The latter should resolve to “/foo/a\/b\/c” (IMO) because all other invalid characters (like space) are auto-escaped. What’s the point of the overloaded div operator otherwise?
Re:Why Does Windows Use Backslash as Path Separator?
by glandium on Wednesday April 24, 2024 @07:06PM
(#40150974)
space is a valid character in paths. / is not. Never.
Re:Why Does Windows Use Backslash as Path Separator?
by ldjb on Wednesday April 24, 2024 @07:23PM
(#40151171)
Classic Mac OS used colon (:) as the path separator, so slashes were perfectly acceptable in file and directory names.
Even in modern versions of macOS, the GUI still allows you to create files and folders with slashes in their names; the slashes get recorded as colons in the filesystem.