This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients eryksun, kushal.das, serhiy.storchaka, terry.reedy, Костя Чолак
Date 2017-05-27.14:12:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1495894330.74.0.195236772202.issue30431@psf.upfronthosting.co.za>
In-reply-to
Content
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()"
History
Date User Action Args
2017-05-27 14:12:10terry.reedysetrecipients: + terry.reedy, serhiy.storchaka, kushal.das, eryksun, Костя Чолак
2017-05-27 14:12:10terry.reedysetmessageid: <1495894330.74.0.195236772202.issue30431@psf.upfronthosting.co.za>
2017-05-27 14:12:10terry.reedylinkissue30431 messages
2017-05-27 14:12:10terry.reedycreate