This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: DictReader does not suport line_num
Type: behavior Stage:
Components: Documentation, Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, ivanoe
Priority: normal Keywords:

Created on 2008-03-20 08:46 by ivanoe, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg64160 - (view) Author: (ivanoe) Date: 2008-03-20 08:46
Documentation http://docs.python.org/lib/node264.html mentions that both
'reader' and 'DictReader' support 'line_num' fields.
But in fact in version 2.5.2 of the library line_num is not in
'DictReader' class. (looking at csv.py)

For the moment I created little wrapper class to handle the issue, but
it should be done in the original 'DictReader' to support uniform
'interface' of the reader.
{{{
import csv
class DictReader(csv.DictReader):
    """ DictReader that supports line_num field. """

    def __init__(self, f, fieldnames=None, restkey=None, restval=None,
                 dialect="excel", *args, **kwds):
        csv.DictReader.__init__(self, f, fieldnames, restkey, restval,
dialect)
        self.line_num = 0

    def next(self):
        res = csv.DictReader.next(self)
        self.line_num+=1
        return res
}}}

(sorry, no tests)
I suggest that line_num gets implemented, rather then documentation changed.
msg64268 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-03-21 20:02
Fixed by adding line_num attr to DictReader in r61712, r61713 (2.5).
History
Date User Action Args
2022-04-11 14:56:32adminsetgithub: 46684
2008-03-21 20:02:08georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg64268
2008-03-20 08:46:59ivanoecreate