我正在使用以下代码来学习如何使用此网站上的CSV文件进行读取,编写和分析http://www.whit.com.au/blog/2011/11/reading-and-writing-csv-files /.但是,我得到这些错误,
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'
Run Code Online (Sandbox Code Playgroud)
你知道我为什么会收到上述错误吗?我正在使用Notepad ++和PowerShell.我实际上环顾四周,试图找到一个CSV模块供python下载,但我没有找到任何.我有点失落.
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()
Run Code Online (Sandbox Code Playgroud)
在旁注中,我很有兴趣在如何在python中读取,编写和使用CSV文件的好教程.
| 归档时间: |
|
| 查看次数: |
7235 次 |
| 最近记录: |