我正在尝试读取 text.txt 文件中的第二行:
import fileinput
x = 0
for line in fileinput.input([os.path.expandvars("$MYPATH/text.txt")]):
if x < 3:
x += 1
if x == 2:
mydate = line
fileinput.close()
print "mydate : ", mydate
但我收到一个错误:
Traceback (most recent call last):
File "/tmp/tmpT8RvF_.py", line 4, in <module>
for line in fileinput.input([os.path.expandvars("$MYPATH/text.txt")]):
File "/usr/lib64/python2.6/fileinput.py", line 102, in input
raise RuntimeError, "input() already active"
RuntimeError: input() already active
上面有什么问题?