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

Why exception from os.path.exists()?

On 2018-06-07 08:45, Chris Angelico wrote:
> On Thu, Jun 7, 2018 at 1:55 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> On Tue, 05 Jun 2018 23:27:16 +1000, Chris Angelico wrote:
>>> And an ASCIIZ string cannot contain a byte value of zero. The parallel
>>> is exact.
>> Why should we, as Python programmers, care one whit about ASCIIZ strings?
>> They're not relevant. You might as well say that file names cannot
>> contain the character "?" because ASCIIZ strings don't support it.
>> No they don't, and yet nevertheless file names can and do contain
>> characters outside of the ASCIIZ range.
> Under Linux, a file name contains bytes, most commonly representing
> UTF-8 sequences. So... an ASCIIZ string *can* contain that character,
> or at least a representation of it. Yet it cannot contain "\0".
I've seen a variation of UTF-8 that encodes U+0000 as 2 bytes so that a 
zero byte can be used as a terminator.

It's therefore not impossible to have a version of Linux that allowed a 
(Unicode) "\0" in a filename.