str的我是新來pyhton我試圖運行此代碼:unicode的,而不是在蟒蛇
with io.open(outfile, 'w') as processed_text, io.open(infile, 'r') as fin:
for line in fin:
processed_text.write(preprocess(line.rstrip())+'\n')
,但得到TypeError: must be unicode, not str
我該怎麼解決呢?我在這裏搜索了類似的問題,發現一個嘗試像
with io.open(outfile, 'w', encoding="utf-8") as processed_text, io.open(infile, 'r') as fin:
但沒有奏效。
請用你的文件例子(outfile和infile)編輯你的問題 – Giordano
看起來像你的'preprocess'函數返回一個'str'而不是'unicode'。 – sirfz
我編輯了預處理帖子 – user1