osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why exception from os.path.exists()?


On 08-06-18 05:12, Ben Finney wrote:
> That is immediately followed by more specific advice that says when to
> use bytes:
>
>     Unfortunately, some file names may not be representable as strings
>     on Unix, so applications that need to support arbitrary file names
>     on Unix should use bytes objects to represent path names. Vice
>     versa, using bytes objects cannot represent all file names on
>     Windows (in the standard mbcs encoding), hence Windows applications
>     should use string objects to access all files.
>
> (That needs IMO a correction, because as already explored in this
> thread, it's not Unix or Windows that makes the distinction there. It's
> the specific *filesystem type* which records either bytes or text, and
> that is true no matter what operating system happens to be reading the
> filesystem.)

But it is the Unix or Windows api that is used. If the unix-api wants
bytes, then you don't have to care about what ends up on the file-system.
Just as you don't care whether the file-system uses encryption or not
to store it's data. That is all hidden in layers that are normally
inaccessible to the user.

Maybe some FS that is hooked up to my linux box does allow embedded NUL
bytes. I won't be able to notice that because even if there are such
files, they will need some remapping in order to make them accessible.
To the user the actuale filenames are the remapped filenames, not what
is actually on the FS.

-- 
Antoon Pardon.