我最近将我的python版本从2.6升级到3.6.3。下面的代码在使用list函数时抛出异常。我发现代码仅对记录超过255的文件失败。不确定如何解决此问题,感谢您的帮助。
try:
with open(filePath) as f:
fileReader = csv.reader(f, delimiter='\t', quoting=csv.QUOTE_NONE)
fileAsList = list(fileReader)
return fileAsList
except:
print ("Oops!! Can't get that file.")
答案 0 :(得分:0)
我通过在打开文件时添加编码来解决问题。下面的代码工作:
try:
with open(filePath, 'r', encoding='latin1') as f:
fileReader = csv.reader(f, delimiter='\t',
quoting=csv.QUOTE_NONE)
fileAsList = list(fileReader)
return fileAsList
except:
print ("Oops!! Can't get that file.")