6
一時ファイルを作成して書き込むことができますが、ファイル行を読み込むと空白になります。私は一時ファイルに内容があることを確認しました。ここに私のコードです。おかげtemp.readline()が空ですか?
import tempfile
temp = tempfile.NamedTemporaryFile()
with open("~/somefile.txt") as inf:
for line in inf:
if line==line.lstrip():
temp.write(line)
line = str(temp.readline()).strip()
print line #nothing
どうすればドキュメントの "シーク"が見えないのですか "10.6。tempfile - 一時ファイルとディレクトリを生成する"これは動作しており、ありがとうございます。 – fpena06
@ fpena06: 'NamedTemporaryFile()'は "ファイルのようなオブジェクト"を返します。ファイルオブジェクトのドキュメントは次のとおりです。http://docs.python.org/library/stdtypes.html#file-objects – NPE