Why exception from os.path.exists()?

Peter J. Holzer hjp-python at hjp.at
Sun Jun 10 16:38:42 EDT 2018


On 2018-06-10 09:45:06 -0500, Bev in TX wrote:
> On Jun 10, 2018, at 5:49 AM, Peter J. Holzer <hjp-python at hjp.at> wrote:
> > On 2018-06-07 12:47:15 +0000, Steven D'Aprano wrote:
> >> But it doesn't do that. "Pathnames cannot contain NUL" is a falsehood 
> >> that programmers wrongly believe about paths. HFS Plus and Apple File 
> >> System support NULs in paths.
> > [...]
> >> But in the spirit of compromise, okay, let's ignore the existence of file 
> >> systems like HFS which allow NUL. Apart from Mac users, who uses them 
> >> anyway? Let's pretend that every file system in existence, now and into 
> >> the future, will prohibit NULs in paths.
[...]
> >  * One with an embedded / in the file name
> 
> This is easily done in Finder, where I created a folder named "my/slash”.  
> When I list it at the command line in Terminal, this shows up as "my:slash”, with the slash shown as a colon.  
> If I create a file with a colon in its name at the command line, that file name acts the same way:
> 
> $ touch ‘my:colon"
> $ ls
> my:colon
> my:slash
> 
> In Finder they both display as:
> my/colon
> my/slash

Thanks. So they just map '/' to ':'. IIRC, MacOS <= 9 used ':' as the
directory separator, so that makes sense. They kept the old behaviour
for applications using the Mac API (and for the GUI), but for the POSIX
API they use '/' (as they have to). Since ':' wasn't previously allowed,
there is no conflict, just some confusion for the users who sees
different filenames depending on which tool they use.

It does, however, mean that on MacOS filenames can't contain all Unicode
characters, either.

[...]
> I added printing the file name.  As suspected, the “slash” is a colon:
> 
> . - 56096374 - 2e
> .. - 56095464 - 2e 2e
> .DS_Store - 56109197 - 2e 44 53 5f 53 74 6f 72 65
> my:colon - 56095933 - 6d 79 3a 63 6f 6c 6f 6e
> my:slash - 56095521 - 6d 79 3a 73 6c 61 73 68

Yup.


> > Bonuspoints for doing this on an USB stick and then mounting the USB
> > stick on a Linux system and posting the output there as well.
> > 
> Sorry, I don’t have Linux, but I suspect it’s the same as the macOS command line.

Very likely, yes.

        hp

-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp at hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20180610/cb06131b/attachment.sig>


More information about the Python-list mailing list