奇怪的重定向效果与raw_inpu

2024-04-23 17:40:00 发布

您现在位置:Python中文网/ 问答频道 /正文

根据manualraw_input写入标准输出。我有一个小程序(test_raw_input.py):

# Test if rawinput writes to stdout or stderr
raw_input('This is my prompt > ')

不管我怎么做:

^{pr2}$

或者

$ python test_raw_input.py 2> xxx

提示总是以xxx结尾。为什么会这样?在


Tags: ortopytest程序input标准raw
1条回答
网友
1楼 · 发布于 2024-04-23 17:40:00

从你对肯尼特的反应来看,我想你明白了

python test_raw_input.py > xxx

只有第二种用法你不明白:

^{pr2}$

我认为您遇到了这里描述的行为http://mail.python.org/pipermail/python-dev/2008-January/076446.html,这导致了错误报告http://bugs.python.org/issue1927,其中有一条评论说它在去年9月还没有修复。在

但是,有一个解决方法:从https://groups.google.com/forum/?fromgroups=#!topic/chennaipy/R_VJYNdel-o开始,如果

^{3}$

在使用raw_input之前,行为将如您所期望的那样。在

相关问题 更多 >