with zipfile.ZipFile("5.csv.zip", "r") as zfile:
for name in zfile.namelist():
with zfile.open(name, 'rU') as readFile:
line = readFile.readline()
print(line)
split = line.split('\t')
它回答:
b'$0.0\t1822\t1\t1\t1\n'
Traceback (most recent call last)
File "zip.py", line 6
split = line.split('\t')
TypeError: Type str doesn't support the buffer API
如何打開文本文件作爲unicode而不是作爲b
?
它看起來像我的zip庫不支持「open」的編碼參數。如果這是正確的,我認爲你將不得不使用'codecs.EncodedFile'包裝或手動解碼每一行。 –
我該怎麼做? –
你知道文件的正確編碼嗎?它看起來像utf-8,但猜測你是否可以避免它是個壞主意。 –