[New-bugs-announce] [issue2432] DictReader does not suport line_num

ivanoe report at bugs.python.org
Thu Mar 20 09:47:00 CET 2008


New submission from ivanoe <ivanoe at ivanoe.net>:

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.

----------
assignee: georg.brandl
components: Documentation, Library (Lib)
messages: 64160
nosy: georg.brandl, ivanoe
severity: normal
status: open
title: DictReader does not suport line_num
type: behavior
versions: Python 2.5

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2432>
__________________________________


More information about the New-bugs-announce mailing list