jdunck / python-unicodecsv

Python2's stdlib csv module is nice, but it doesn't support unicode. This module is a drop-in replacement which *does*. If you prefer python 3's semantics but need support in py2, you probably want https://github.com/ryanhiebert/backports.csv
Other
594 stars 87 forks source link

Reader not iterable on Python3 #52

Closed jruere closed 9 years ago

jruere commented 9 years ago

This works on Python2 and with the build in module.

Python 3.4.3 (default, Mar 25 2015, 17:13:50) 
[GCC 4.9.2 20150304 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import unicodecsv
>>> import io
>>> r = unicodecsv.reader(io.BytesIO(b"hello,world"))
>>> list(r)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: iter() returned non-iterator of type 'UnicodeReader'
tsroten commented 9 years ago

The reason why this is happening is that __next__() is not defined for the UnicodeReader. Python 2 uses the next() method and Python 3 uses the __next__() magic method. Unfortunately, that's the least of the problems with unicodecsv's UnicodeReader iterating in Python 3. The other problems are:

jruere commented 9 years ago

OK, I guess it's not quite ready yet. :)

jdunck commented 9 years ago

I've added py3 in 0.12.0 - please try it out and open another issue if you find specific problems. :)