在OSX下的Python3.2中,如果我运行“type(标准输入)“在空闲状态下,我得到一个奇怪的答案,如下所示
>>> type(sys.stdin)
<class 'idlelib.rpc.RPCProxy'>
>>>
但如果我在终端下重新执行同样的命令,我会得到:
^{pr2}$我明白这是因为我在空闲状态下运行。但这不是误导吗?在
我试图在空闲状态下运行以下命令,并花了数小时试图理解为什么这不起作用。(我还是个Python呆子)
>>> w = sys.stdin.readlines()
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
w = sys.stdin.readlines()
AttributeError: readlines
但刚发现我在终端下工作得很好。在
>>> w = sys.stdin.readlines()
wow
ww
wewew
>>>
>>> w
['wow\n', 'ww\n', 'wewew\n']
>>>
这是虫子吗?在
这是一个归档的Python bug:
http://bugs.python.org/issue9290
请注意,这可能不是固定的,因为
readlines
通常不起作用。相反,您可以只迭代文件对象本身:相关问题 更多 >
编程相关推荐