2016-04-03 10 views
0

私はPythonを初めて学びました。Python:TypeError:Unicodeに強制する:必要な文字列またはバッファー、モジュールが見つかりました

私はファイルの1つを入力していますが、私は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 

いずれかが、このしてくださいに私を助けてもらえます。

+2

ファイルをまったく開く必要はありません。 'fileinput'モジュールが実際に何をするのかを見てください。 – kindall

答えて

0

この特定の問題は、下の行にある:

with open(fileinput,'r') as myfile: 
fileinput

モジュールです。私はあなたが持っていると思います:

with open(fileinput.filename(),'r') as myfile: 
関連する問題