2 ms·
Yep. Drives me nuts when I see people fiddling with platform-specific path separators. Just use /, it works everywhere.
by coldpie 3y ago
Yep. Drives me nuts when I see people fiddling with platform-specific path separators. Just use /, it works everywhere.
- PaulHoule 3y agoI am really in the habit of using pathlib in Python and similar facilities in Java so I just write path = HOME / "cards" / f"{card_id}" / "card.yaml"
- coldpie 3y agoYou 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.
- skinner927 3y agoI 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?
- glandium 3y agospace is a valid character in paths. / is not. Never.
- ldjb 3y agoClassic 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.
- Zamicol 3y agoIt's been years since I've had to work on a Windows system, but I'm suspicious of that. Days of my career at the State of Colorado has been spent fixing / problems. Is this something on newer Windows systems?
- coldpie 3y agoIf you're mucking around with legacy parts of the OS, you might run into troubles. But if you're just doing regular old file I/O from a normal program, nah. Windows doesn't care. You can even mix them.
- RedlineTriad 3y agoThis sadly isn't quite the case as this post demonstrates[0] > - The path is limited to MAX_PATH (260 chars) > - Unless you prefix the path with \\?\ > - However using \\?\ disables automatic conversion of / to \ in the path (and some other normalization) See previous discussion[1] [0] https://mastodon.gamedev.place/@AshleyGullen/111109299141510319 https://mastodon.gamedev.place/@AshleyGullen/111109299141510... [1] https://news.ycombinator.com/item?id=37632232 https://news.ycombinator.com/item?id=37632232