我正在使用下面的代码来学习如何从这个网站http://www.whit.com.au/blog/2011/11/reading-and-writing-csv-files/中读取、写入和分析CSV文件。但是,我知道这些错误,
Traceback (most recent call last): Files "csv_example.py",
line 1, in <module? import csv
File "C:\python27\csv.py", line 11, in <module>
mywriter = csv.writer(csv_out)
AttributeError: 'module' object has no attribute 'writer'你知道我为什么会犯上面的错误吗?我正在使用Notepad++和PowerShell。实际上,我环顾四周,试图找到一个供python下载的CSV模块,但没有找到任何模块。我有点迷路了。
import csv
bus_numbers = ['101', '102', '36', '40']
bus_names = ['NUC_A', 'NUC_B', 'CATDOG', 'HYDRO_A']
voltage = [.99, 1.02, 1.01, 1.00]
# open a file for writing.
csv_out = open('mycsv.csv', 'wb')
# create the csv writer object.
mywriter = csv.writer(csv_out)
# all rows at once.
rows = zip(bus_numbers, bus_names, voltage)
mywriter.writerows(rows)
# always make sure that you close the file.
# otherwise you might find that it is empty.
csv_out.close()在一个侧面,我感兴趣的是关于如何在python中读取、编写和使用CSV文件的好教程。
发布于 2013-10-15 01:57:55
这是一个常见的错误。将脚本从csv.py重命名为其他内容;在执行import csv时,它将尝试导入自己。
https://stackoverflow.com/questions/19372111
复制相似问题