Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DictReader has a different interface from csv.DictReader #1

Closed
lucaswiman opened this issue Feb 24, 2018 · 2 comments · Fixed by #2
Closed

DictReader has a different interface from csv.DictReader #1

lucaswiman opened this issue Feb 24, 2018 · 2 comments · Fixed by #2

Comments

@lucaswiman
Copy link
Contributor

The csv342 version of DictReader cannot accept a list of CSV lines, though the built in version in both Python 2 and Python 3 can do so. If you're interested in accepting patches, I could submit one for this issue.

csv342 on python 2.7

>>> import csv342 as csv
>>> list(csv.DictReader(['a,b', '1,2']))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/lucaswiman/website/vendor/venv/lib/python2.7/site-packages/csv342.py", line 239, in next
    return self.__next__()
  File "/Users/lucaswiman/website/vendor/venv/lib/python2.7/site-packages/csv342.py", line 220, in __next__
    if self.fieldnames is None:
  File "/Users/lucaswiman/website/vendor/venv/lib/python2.7/site-packages/csv342.py", line 205, in fieldnames
    self._set_fieldnames_from_first_row()
  File "/Users/lucaswiman/website/vendor/venv/lib/python2.7/site-packages/csv342.py", line 199, in _set_fieldnames_from_first_row
    self._fieldnames = next(self.reader)
  File "/Users/lucaswiman/website/vendor/venv/lib/python2.7/site-packages/csv342.py", line 161, in next
    return self.__next__()
  File "/Users/lucaswiman/website/vendor/venv/lib/python2.7/site-packages/csv342.py", line 156, in __next__
    row = self.reader.next()
  File "/Users/lucaswiman/website/vendor/venv/lib/python2.7/site-packages/csv342.py", line 140, in next
    return self.__next__()
  File "/Users/lucaswiman/website/vendor/venv/lib/python2.7/site-packages/csv342.py", line 137, in __next__
    return self._text_stream.next().encode('utf-8')
AttributeError: 'list' object has no attribute 'next'

Python 3.4 (also works on 3.6)

>>> import csv
>>> list(csv.DictReader(['a,b', '1,2']))
[{'a': '1', 'b': '2'}]
@roskakori
Copy link
Owner

Yes, please submit a patch.

@roskakori
Copy link
Owner

Version 1.0.0 is released on PyPI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants