我是Python的新手,只是在学习。
我正在将其中一个文件作为输入,我想使用python在控制台上打印文本。
# This will take the file as input
import fileinput
for line in fileinput.input():
print "The file name you provided is " + fileinput.filename()
#file of = open(fileinput, "r", 0)
with open(fileinput,'r') as myfile:
data=myfile.read()
print "This is your actual data \n\n" + data
我遇到的错误是:
TypeError: coercing to Unicode: need string or buffer, module found
请有人帮我解决这个问题。
答案 0 :(得分:0)
这个特殊问题如下:
with open(fileinput,'r') as myfile:
fileinput
是一个模块。我认为你的意思是:
with open(fileinput.filename(),'r') as myfile: