Terry J. Reedy added the comment:
Experiments running 3.6.1 on Windows in console:
>python -c "print('some\0 text')
some text # \0 printed as ' ', as determined by
# >python -c "for c in 'some text': print(ord(c))" printing 32 32
>python -c "input('some\0 text')
some
In IDLE, both print full string with actual null byte. As a result, attempting
the ord() test above generates "SyntaxError: source code string cannot contain
null bytes". Cutting the output from IDLE and pasting here (FireFox) results
in a truncated 'some'.
Conclusions:
1. Python is emitting \0 to stdout. That is what python should do when asked
to, as documented.
2. Currently, if one wants to prompt with strings containing \0, use IDLE or a
similar GUI-based shell.
3. input() should *not* reject prompts with \0
4. If \0 is a problem for a particular stdout, its handler could raise
ValueError, or replace \0 with r'\0', or replace \0 with ' ' (as with print to
Widows console.
5. When running in Windows console, the prompt output part of input(prompt)
should treat \0 the same as print(prompt) does. I am surprised it does not, as
"input(prompt)" has been described as shorthand for "print(prompt, end='');
input()"
----------
nosy: +terry.reedy
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue30431>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com