On 2018-07-01 08:50:22 +0000, Steven D'Aprano wrote: > On Sun, 01 Jul 2018 03:18:23 +0000, eryk sun wrote: > > On Sun, Jul 1, 2018 at 1:44 AM, Steven D'Aprano > > <steve+comp.lang.pyt...@pearwood.info> wrote: > >> I guess that if the user is using a path beginning with \\?\ they may > >> or may not need to use backslashes, but I have no way of testing it, > >> and I would expect that Python will correctly replace //?/ with > >> backslashes the same as it does for any other file system path. > > > > The Windows API handles this, but not for a path that begins with \\?\. > > But what about the *Python* API? The Python open() function, and all the > high-level os.* and os.path.* functions which take paths as strings are > supposed to automatically convert forward slashes to backslashes. Aren't > they?
Are they? I don't see anything in the docs that support this (but maybe my Google Fu is weak). Rather from the existence and design of os.path I conclude that the programmer is supposed to construct path names in the local convention (i.e., you should use os.path.join(dirname, filename) instead of dirname + "/" + filename, which will ensure that the correct separator is used). I think the lazy approach using just forward slashes works because *Windows* treats slashes in filenames like backslashes (most of the time), not because Python converts them. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | h...@hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list