ipython调用fileinput.input()有异常,但是原始的python可以工作

时间:2016-12-01 06:01:16

标签: python exception input file-io ipython

我使用的是python 2.7和ipython2.7。 在ipython中我尝试过:

In [107]: for line in fileinput.input('webrtc_log.txt'):print line
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-107-fd0ede841362> in <module>()
----> 1 for line in fileinput.input('webrtc_log.txt'):print line

    /usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/fileinput.py in input(files, inplace, backup, bufsize, mode, openhook)
    93     global _state
    94     if _state and _state._file:
---> 95         raise RuntimeError, "input() already active"
    96     _state = FileInput(files, inplace, backup, bufsize, mode, openhook)
    97     return _state

RuntimeError: input() already active
In [109]: fh=open('webrtc_log.txt')
In [110]: for line in fh.readlines():print line
Local Date: Mon Nov 28 13:03:47 2016

好的,旧的&#34;打开+ readlines()&#34;有效,但文件输入无效。

我在raw python 2.7命令行下再试一次,两者都运行良好。我想知道ipython如何使用fileinput.input(???)

0 个答案:

没有答案