Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python IDLE stops outputting a string on encountering a null character both for STDOUT and STDERR #119614

Closed
Assignees
serhiy-storchaka
Labels
@A-Paint-Brush

Description

@A-Paint-Brush

Bug report

Bug description:

I noticed that if you pass a string containing a null character (\0) as an argument to the built-inprint function, IDLE only outputs that string to the point of the null character, then it jumps to outputting the next argument to print as if that string has actually ended. This is not consistent with the behavior when using the Python interpreter directly in a terminal, where the null character is usually printed as a space-looking character and does not terminate the string. If further arguments to the sameprint call also contains null characters, the same thing happens (it'll skip to the next argument immediately on encountering a\0). If thesep string contains a null character, it'll also only print to the point of the null character before starting to print the next positional argument, as if thesep string had actually ended there. The same thing happens with theend string. And the same behavior happens when callingsys.stdout.write directly. Writing to STDERR has the same effect of stuff getting cut off on the null character. Basically anything that results in text being outputted to IDLE triggers this bug. Maybe tk's Text widget treats null characters as string terminators because tk is written in C? By the way, the bug works the same both in interactive mode and running a file. Below's an example, run it in IDLE and you should get the same erroneous output:

>>>print("hello\0world!")# expected output: hello world!hello>>>print("wait","what?",sep="\0, ")# expected output: wait , what?waitwhat?>>>print("fo\0o","\0bar","ba\0z","spa\0m","ha\0m","e\0ggs",end=" xyz\0zy\n")# expected: fo o  bar ba z spa m ha m e ggs xyz zyfobaspahaexyz>>>importsys>>>_=sys.stdout.write("same\0here\n")# expected output: same heresame>>> _=sys.stderr.write("in errors\0too\n")# expected output: in errors tooinerrors>>>raiseRuntimeError("something ba\0d happened.")Traceback (mostrecentcalllast):File"<pyshell#5>",line1,in<module>raiseRuntimeError("something ba\0d happened.")RuntimeError:somethingba>>>

Version Info:
I have tested this on the 64 bit "Windows Installer" versions of Python3.9.7 and3.12.3. My OS isWindows 10 Version 22H2, build 19045.4412. Thesys.version value on the 3.9.7 version is3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)], and the 3.12.3 version is3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)]. Hope this helps.

CPython versions tested on:

3.9, 3.12

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp