s*****n 发帖数: 839 | 1 本来我的程序能顺利运行的,后来电脑重装,就装了Python3.2,然后下面的程序就开始
报错了。一开始是找不到next() function, 这个问题已解决。后来是说没有把文件读
成text.我就搞不明白该怎么改了。
程序在这里:
>>> import csv
>>> filename="C:/QWI_2011Q3.csv"
>>> reader=csv.reader(open(filename,'rb'),delimiter=",")
>>> reader.next()
I changed reader.next() to reader.__next__() | l********a 发帖数: 1154 | 2 py3k和py2.x的文档来看就一个差别:
py3k:
"...If csvfile is a file object, it should be opened with newline=''.[1]"
[1] If newline='' is not specified, newlines embedded inside quoted fields
will not be interpreted correctly, and on platforms that use \r\n linendings
on write an extra \r will be added. It should always be safe to specify
newline='', since the csv module does its own (universal) newline handling.
py2.x:
"...If csvfile is a file object, it must be opened with the ‘b’ flag on
platforms where that makes a difference."
没有py3,继续征战2.7,没法帮你测试
用下面改了打开参数的语句试试,可能会好:
>>> ...
>>> reader=csv.reader(open(filename, newline=''),delimiter=",")
>>> ... | s*****n 发帖数: 839 | 3 谢谢回复。
我解决了上面的问题。
用下面的程序就可以:
>>> import csv
>>> r=csv.reader(open("C:/Documents/Project/Python code/practice1/csv/
ATXRNSA.csv"))
>>> line1=r.__next__()
>>> line1 |
|