【发布时间】:2019-02-07 05:09:15
【问题描述】:
我使用 python 3.7
我的代码是:
import csv
file_name = 'num_files/num.csv'
with open(file_name) as file:
reader = csv.reader(file)
print(reader)
我得到了这个结果:
2,5,5,5,33,1,1,9
5
,
Traceback (most recent call last):
File "/Users/johnkievits/Library/Mobile Documents/com~apple~CloudDocs/python_files/csv_test.py", line 6, in <module>
reader = csv.reader(file)
AttributeError: module 'csv' has no attribute 'reader'
[Finished in 0.1s with exit code 1]
我有两个问题:
首先:昨天代码运行良好。刚拿到前两行。 “回溯”在晚上突然来了。这怎么可能?
第二:我的目标是从第一行获取 te 值。他们现在将自己呈现为:
2,5,5,5,33,1,1,9
第二行的“5”不是一个值! 我想实现每个值都分配给一个变量。
还有一件奇怪的事情。当我在终端中运行代码时(我使用的是 Mac),我没有得到回溯错误! 只出现两行。第二行不是 csv 文件中的值!
我希望一位更有经验的用户可以帮助我重新上路并帮助我解决这两个问题。谢谢!
【问题讨论】: