[issue1818] Add named tuple reader to CSV module

Jervis Whitley report at bugs.python.org
Mon Mar 9 00:13:34 CET 2009


Jervis Whitley <jervisau at gmail.com> added the comment:

Antoine> I don't understand why NamedTupleReader requires the 
Antoine> fieldnames array
Antoine> rather than the namedtuple class itself. If you could pass it
Antoine> the namedtuple class, users could choose whatever namedtuple 
Antoine> subclass with whatever additional methods or behaviour suits
Antoine> them. It would make NamedTupleReader more flexible and more 
Antoine> useful.

The NamedTupleReader does take the namedtuple class as the fieldnames
argument. It can be a namedtuple, a 'fieldnames' array or None. 
If a namedtuple is used as the fieldnames argument, returned rows are
created using ._make from the this namedtuple. Unless I have read your
requirements incorrectly, this is the behaviour you describe.

Given the confusion, I accept that the documentation needs to be improved. 

The NamedTupleReader and Writer were created to follow as closely as
possible the behaviour (and signature) of the DictReader and DictWriter,
with the exception of using namedtuples instead of dicts.

----------
message_count: 27.0 -> 28.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1818>
_______________________________________


More information about the Python-bugs-list mailing list