gpt4 book ai didi

python - <_io.TextIOWrapper 名称 ='canc.csv' 模式 ='r' 编码 ='cp1252' > 错误在 python 中意味着什么?

转载 作者:太空宇宙 更新时间:2023-11-04 05:10:31 25 4
gpt4 key购买 nike

我想在 python 中打开一个 CSV 文件,但我一次又一次地遇到这个错误。这是我的代码:

import csv
with open("canc.csv","r") as csvFile:
reader = csv.reader(csvFile)
data = []
for row in reader:
if len(row) !=0:
data = data + [row]
csvFile.close()
print(csvFile)`

最佳答案

在您的代码中,csvFile是一个文件,而不是您读入 data 的内容

事实上,正如 print 告诉您的那样,它是一个 TExtIOWrapper,具有名称、模式和编码:<_io.TextIOWrapper name='canc.csv' mode='r' encoding='cp1252'>

如果你想查看文件中的数据,只需使用

print(data)

关于python - <_io.TextIOWrapper 名称 ='canc.csv' 模式 ='r' 编码 ='cp1252' > 错误在 python 中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43115279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com