我发现了
input('some\x00 text')
Run Code Online (Sandbox Code Playgroud)
将提示some而不是some text.
从消息来源,我发现这个函数使用C函数PyOS_Readline,它在NULL字节后忽略提示中的所有内容.
来自PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt):
fprintf(stderr, "%s", prompt);
Run Code Online (Sandbox Code Playgroud)
https://github.com/python/cpython/blob/3.6/Python/bltinmodule.c#L1989 https://github.com/python/cpython/blob/3.6/Parser/myreadline.c#L251
这是一个错误还是有原因的?