python的版本为 2.7.13 。
3.txt的内容是:
this is a river
that is a cloud
the world is beatiful
我写了一个python脚本:
import fileinput
def process(string):
print 'Processing: ', string
for line in fileinput.input(r'E:\Python\3.txt'):
process(line)
当我运行此脚本时,它报告错误:
====================== RESTART: E:\Python\fileinput.py ======================
Traceback (most recent call last):
File "E:\Python\fileinput.py", line 1, in <module>
import fileinput
File "E:\Python\fileinput.py", line 7, in <module>
for line in fileinput.input(r'E:\Python\3.txt'):
AttributeError: 'module' object has no attribute 'input'
--------------------------------------------------------------------------------
引起此问题的原因是什么?
我该如何解决这个问题?
答案 0 :(得分:2)
不要将脚本命名为“ fileinput.py”。它与同名的库模块冲突。