On Mon, 14 Feb 2022 at 05:15, Eric Fahlgren <ericfahlg...@gmail.com> wrote:
>
> On Sun, 13 Feb 2022 at 15:43, Chris Angelico <ros...@gmail.com> 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 -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/WQTHYRZKGBTGPHMEU7QP2PV23UODCLAW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to