On Mon, 14 Feb 2022 at 05:15, Eric Fahlgren <[email protected]> wrote:
>
> On Sun, 13 Feb 2022 at 15:43, Chris Angelico <[email protected]> wrote:
>>
>> > it to. If I'm on Windows and I tell something to write to a file in
>> > "%TEMP%\spam.csv", then I expect it to understand what that means.
>> > Cross-platform support is nice, but the most common need is for the
>> > current platform's normal behaviour.
>
>
> That may or may not work as Windows has inconsistent treatment of multiple
> separators depending on where they appear in a path. If TEMP is a drive
> spec, say "t:\", then it expands to "t:\\spam.csv", which is an invalid
> windows path. If TEMP is a directory spec, "c:\temp\", then it expands to
> "c:\temp\\spam.csv", which works fine.
>
> C:\> dir c:\\temp\junk
> The filename, directory name, or volume label syntax is incorrect.
>
> C:\> dir c:\temp\\junk
> Volume in drive C has no label.
> Volume Serial Number is FC52-C692
> Directory of c:\temp
> 2022-02-13 10:09 0 junk
Ugh, what a mess. Thanks for the reminder that I don't understand
Windows very well. In my defense, I haven't used it much in years, so
I'm not sure what the best practice would be here; but I do know that,
if there is such a thing as best practice,
Path("%TEMP%\\spam.csv").expandvars() should do it. (Or
os.path.expandvars(Path("%TEMP%\\spam.csv")) or however it's spelled.)
At least Unix has it written into the standard that multiple slashes
are equivalent to one.
ChrisA
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/WQTHYRZKGBTGPHMEU7QP2PV23UODCLAW/
Code of Conduct: http://python.org/psf/codeofconduct/