4 ms·
>>>open(b'test-\xd8\x00.txt', 'w').close() Is that a C-string? Does it crash if one forgets the null byte?
by the8472 10y ago
>>>open(b'test-\xd8\x00.txt', 'w').close()
Is that a C-string? Does it crash if one forgets the null byte?
- throwawayish 10y agoThis specific example would not work, since NUL bytes are not allowed in file names. open(b'test-\xd8\x01.txt', 'w').close() Makes the same point. Note that b'test-\xd8\x00.txt' is totally valid. You just can't use that as a file name.
- 6Typos 10y agoRunning that gave: >>> open(b'test-\xd8\x00.txt', 'w').close() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: embedded NUL character So yeah, TypeError Edit: Formatting
- guitarbill 10y agoNo, it is not a C-string. Python remembers string length regardless of null bytes.
- masklinn 10y ago> Is that a C-string? It's a Python bytestring. > Does it crash if one forgets the null byte? No. But in that case it will crash when you use it as CPython (and most FS APIs, and most FS) don't allow NUL in filenames.
- pvg 10y agoIt's not going to crash. You'll get an error.
- Sir_Cmpwn 10y agoMy bad, pushed a fix to use \x01.