【发布时间】:2016-04-06 01:04:09
【问题描述】:
我是 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
谁能帮帮我。
【问题讨论】:
-
您根本不需要打开文件。看看
fileinput模块实际上做了什么。