Non-unicode file names
Cameron Simpson
cs at cskk.id.au
Wed Aug 8 22:39:49 EDT 2018
On 09Aug2018 03:14, MRAB <python at mrabarnett.plus.com> wrote:
[...]
>>>Is it true that Unix filenames can contain control characters, e.g. \x07?
Yep. They're just byte strings. You can't have \0 (NUL) because the API uses
NUL terminated strings, and you can't use slash '/' in the filename components
because that is the component separator. But otherwise you can basicly use
anything - the OS itself doesn't care.
There are some (platform dependent) length limits, and the underlying mounted
filesystem you're accessing may itself have special rules (eg nonUNIX
filesystems like FAT32, etc).
>>>When happens when you print them out?
They get written out? If you're printing to a terminal of some kind then it
will do whatever the bytes from the filename tell it to, as that's what
terminals do.
>>>>>import sys; import subprocess
>>>>>subprocess.call([sys.executable, '\x07.py'])
>>.py
>>0
>>>>>
>>
>>As you might expect, it beeped when printing '\x07.py' (and showed .py)
>>
>And that's OK, is it? :-)
Of course it is :-) \07 is the ASCII BEL character, so it rings the terminal's
bell. Modern software terminals emulate that to a better or worse degree.
Suppose you're verbally reciting a filename (or, of course, printing the
filename to a voder). Only Victor Borge will provide a full verbal
pronunciation of things [1]
[1] https://www.youtube.com/results?search_query=victor+gorge+phonetic+punctuation
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list