私は同じことをする(テキストファイルを処理して結果をアウトファイルに保存する)コードの2つの例を持っています。 しかし、これは私のために動作しません:Pythonコーデックでファイルを保存する
with codecs.open('outfile.txt', 'w', 'utf-8') as outfile:
for f in os.listdir(my_files):
outfile.write(some_function(codecs.open(f, 'r', 'utf-8')))
outfile.write('\n')
これは完璧に動作に対し:
outfile = open('outfile.txt', 'w')
for f in os.listdir(my_files)
with open(f) as f_:
text = f_.read().decode('utf-8')
text = some_function(text)
outfile.write(text.encode('utf-8'))
outfile.write('\n')
私は、Pythonのコーデックと間違って何かをやっていますか? ありがとうございました!
このエラーを出力しますか? :) – Roelant