[issue1818] Add named tuple reader to CSV module

2020-12-21 Thread Raymond Hettinger
Change by Raymond Hettinger : -- stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___ Python-bugs-list m

[issue1818] Add named tuple reader to CSV module

2018-01-29 Thread Skip Montanaro
Skip Montanaro added the comment: FWIW, I relinquished my check-in privileges quite awhile ago. This should almost certainly no longer be assigned to me. S -- ___ Python tracker __

[issue1818] Add named tuple reader to CSV module

2018-01-29 Thread Raymond Hettinger
Change by Raymond Hettinger : -- priority: low -> normal versions: +Python 3.8 -Python 3.5 ___ Python tracker ___ ___ Python-bugs-list

[issue1818] Add named tuple reader to CSV module

2015-05-28 Thread Cédric Krier
Changes by Cédric Krier : -- nosy: +ced ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/

[issue1818] Add named tuple reader to CSV module

2015-05-11 Thread Skip Montanaro
Skip Montanaro added the comment: I looked at this six years ago. I still haven't found a situation where I pined for a NamedTupleReader. That said, I have no objection to committing it if others, more well-versed in current Python code and NamedTuples than I gives it a pass. Note that I added

[issue1818] Add named tuple reader to CSV module

2015-05-10 Thread Ilia Kurenkov
Ilia Kurenkov added the comment: Friendly reminder that this exists. I know everyone's busy and this is marked as low-priority, but I'm gonna keep bumping this till we add a solution :) -- ___ Python tracker _

[issue1818] Add named tuple reader to CSV module

2015-04-19 Thread Raymond Hettinger
Raymond Hettinger added the comment: Skip or Barry, do you want to look at this? -- assignee: -> skip.montanaro nosy: +skip.montanaro stage: needs patch -> patch review versions: -Python 3.3 ___ Python tracker ___

[issue1818] Add named tuple reader to CSV module

2015-04-19 Thread Ilia Kurenkov
Ilia Kurenkov added the comment: As my contribution during the sprints at PyCon 2015, I've tweaked Jervis's patch a little and updated the tests/docs to work with Python 3.5. My only real change was placing the basic reader object inside a generator expression that filters out empty lines. Bei

[issue1818] Add named tuple reader to CSV module

2015-02-10 Thread Daniel Lenski
Daniel Lenski added the comment: Here's the class I have been using for reading namedtuples from CSV files: from collections import namedtuple from itertools import imap import csv class CsvNamedTupleReader(object): __slots__ = ('_r', 'row', 'fieldnames') def __i

[issue1818] Add named tuple reader to CSV module

2014-02-03 Thread Mark Lawrence
Changes by Mark Lawrence : -- nosy: -BreamoreBoy ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.p

[issue1818] Add named tuple reader to CSV module

2012-12-13 Thread Andrew Svetlov
Changes by Andrew Svetlov : -- nosy: +asvetlov ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.pytho

[issue1818] Add named tuple reader to CSV module

2012-09-06 Thread Ahsan Nawroj
Changes by Ahsan Nawroj : -- nosy: -ainur0160 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.pytho

[issue1818] Add named tuple reader to CSV module

2012-09-06 Thread Ahsan Nawroj
Changes by Ahsan Nawroj : -- nosy: +ainur0160 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python

[issue1818] Add named tuple reader to CSV module

2010-09-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: Unassigning, this needs fresh thought and a fresh patch from someone who can devote a little deep thinking on how to solve this problem cleanly. In the meantime, it is no problem to simply cast the CSV tuples into named tuples. -- assignee: rhetti

[issue1818] Add named tuple reader to CSV module

2010-07-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: Re-opening because we ought to do something along these lines at some point. The DictReader and DictWriter are inadequate for preserving order and they are unnecessarily memory intensive (one dict per record). FWIW, the non-conforming field name problem

[issue1818] Add named tuple reader to CSV module

2010-07-25 Thread Mark Lawrence
Mark Lawrence added the comment: Closing as no response to msg110598. -- status: pending -> closed ___ Python tracker ___ ___ Python-b

[issue1818] Add named tuple reader to CSV module

2010-07-17 Thread Mark Lawrence
Mark Lawrence added the comment: I suggest that this is closed unless anyone shows an active interest in it. -- nosy: +BreamoreBoy status: open -> pending versions: +Python 3.2, Python 3.3 -Python 2.7, Python 3.1 ___ Python tracker

[issue1818] Add named tuple reader to CSV module

2010-05-20 Thread Skip Montanaro
Changes by Skip Montanaro : -- nosy: -skip.montanaro ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mai

[issue1818] Add named tuple reader to CSV module

2010-04-12 Thread Skip Montanaro
Skip Montanaro added the comment: Type conversion is a whole 'nuther kettle of fish. This particular thread is long and complex enough that it shouldn't be made more complex. -- ___ Python tracker ___

[issue1818] Add named tuple reader to CSV module

2010-04-12 Thread Éric Araujo
Éric Araujo added the comment: See also this python-ideas thread: http://mail.python.org/pipermail/python-ideas/2010-April/006991.html -- nosy: +merwok ___ Python tracker ___ __

[issue1818] Add named tuple reader to CSV module

2009-03-08 Thread Jervis Whitley
Jervis Whitley added the comment: Updated version of docs for 2.7 and 3k. -- message_count: 29.0 -> 30.0 Added file: http://bugs.python.org/file13274/ntreader6_py3.diff ___ Python tracker __

[issue1818] Add named tuple reader to CSV module

2009-03-08 Thread Jervis Whitley
Changes by Jervis Whitley : Added file: http://bugs.python.org/file13275/ntreader6_py27.diff ___ Python tracker ___ ___ Python-bugs-list mailin

[issue1818] Add named tuple reader to CSV module

2009-03-08 Thread Jervis Whitley
Changes by Jervis Whitley : Removed file: http://bugs.python.org/file13268/ntreader5_py3_1.diff ___ Python tracker ___ ___ Python-bugs-list mai

[issue1818] Add named tuple reader to CSV module

2009-03-08 Thread Antoine Pitrou
Antoine Pitrou added the comment: Ok, I got misled by the documentation ("The contents of *fieldnames* are passed directly to be used as the namedtuple fieldnames"), and your implementation is a bit difficult to follow. -- message_count: 28.0 -> 29.0 ___

[issue1818] Add named tuple reader to CSV module

2009-03-08 Thread Jervis Whitley
Jervis Whitley 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

[issue1818] Add named tuple reader to CSV module

2009-03-08 Thread Jervis Whitley
Jervis Whitley added the comment: Jervis> in csv.rst removed reference to reader.next() as a public method. Skip> Because? I've not seen any discussion in this issue or in any Skip> other forums Skip> (most certainly not on the c...@python.org mailing list) which would Skip> suggest Skip> that

[issue1818] Add named tuple reader to CSV module

2009-03-08 Thread Skip Montanaro
Skip Montanaro added the comment: I retract my previous comment. I don't use the DictReader the way it operates (fieldnames==None => first row is a header) and forgot about that behavior. -- message_count: 25.0 -> 26.0 ___ Python tracker

[issue1818] Add named tuple reader to CSV module

2009-03-08 Thread Skip Montanaro
Changes by Skip Montanaro : -- message_count: 26.0 -> 25.0 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http:

[issue1818] Add named tuple reader to CSV module

2009-03-08 Thread Skip Montanaro
Skip Montanaro added the comment: I find this aspect of the proposal disturbing: If *fieldnames* is None the values in the first row of the *csvfile* will be used as the fieldnames I don't think this should be implicit. It makes the NamedTupleReader semantically different fr

[issue1818] Add named tuple reader to CSV module

2009-03-08 Thread Skip Montanaro
Skip Montanaro added the comment: I don't know how NamedTuple objects work, but in many situations you want the content of the CSV file to drive the output. I would think you would use a technique similar to my DictReader example to tell the NamedTupleReader the fieldnames. For that you need a

[issue1818] Add named tuple reader to CSV module

2009-03-08 Thread Antoine Pitrou
Antoine Pitrou added the comment: I don't understand why NamedTupleReader requires the fieldnames array rather than the namedtuple class itself. If you could pass it the namedtuple class, users could choose whatever namedtuple subclass with whatever additional methods or behaviour suits them. It

[issue1818] Add named tuple reader to CSV module

2009-03-07 Thread Skip Montanaro
Skip Montanaro added the comment: Jervis> in csv.rst removed reference to reader.next() as a public method. Because? I've not seen any discussion in this issue or in any other forums (most certainly not on the c...@python.org mailing list) which would suggest that csv.reader's next() method sh

[issue1818] Add named tuple reader to CSV module

2009-03-07 Thread Jervis Whitley
Jervis Whitley added the comment: Added a patch against py3k branch. in csv.rst removed reference to reader.next() as a public method. Added file: http://bugs.python.org/file13263/ntreader4_py3_1.diff ___ Python tracker _

[issue1818] Add named tuple reader to CSV module

2009-02-26 Thread Skip Montanaro
Skip Montanaro added the comment: Rob> I still don't like the lack of symmetry of supporting implicit Rob> header reads, but not implicit header writes. A header is nothing more than a row in the CSV file with special interpretation applied by the user. There is nothing implicit about it.

[issue1818] Add named tuple reader to CSV module

2009-02-26 Thread Raymond Hettinger
Raymond Hettinger added the comment: > I don't think you should write them by default. > I've worked with lots of CSV files which have no headers. My experience has been the same as Skips. ___ Python tracker ___

[issue1818] Add named tuple reader to CSV module

2009-02-26 Thread Rob Renaud
Rob Renaud added the comment: I did a search on Google code for the DictReader constructor. I analyzed the first 3 pages, the fieldnames parameter was used in 14 of 27 cases (discounting unittest code built into Python) and was not used in 13 of 27 cases. I suppose that means headered csv file

[issue1818] Add named tuple reader to CSV module

2009-02-26 Thread Skip Montanaro
Skip Montanaro added the comment: More concretely, I don't think this is so onerous: names = ["col1", "col2", "color"] writer = csv.DictWriter(open("f.csv", "wb"), fieldnames=names, ...) writer.writerow(dict(zip(names, names))) ... or f = open("f.csv", "rb") names = cs

[issue1818] Add named tuple reader to CSV module

2009-02-26 Thread Skip Montanaro
Skip Montanaro added the comment: Rob> I agree that we should not unconditionally write headers, but I Rob> think that we should write headers by default, much like we read Rob> them by default. I don't think you should write them by default. I've worked with lots of CSV files which ha

[issue1818] Add named tuple reader to CSV module

2009-02-26 Thread Rob Renaud
Rob Renaud added the comment: I want to make sure I understand. Am I correct in believing that Skip thinks writing headers should be optional, while Jervis believes we should leave the burden to the NamedTupleWriter client? I agree that we should not unconditionally write headers, but I thin

[issue1818] Add named tuple reader to CSV module

2009-02-26 Thread Jervis Whitley
Jervis Whitley added the comment: Skip> Let me be more explicit. I don't know how it implements it, but I think Skip> you really need to give the user the option of specifying the field Skip> names and not reading/writing headers. It can't be implicit as I Skip> interpreted Rob's earlier com

[issue1818] Add named tuple reader to CSV module

2009-02-26 Thread Skip Montanaro
Skip Montanaro added the comment: Let me be more explicit. I don't know how it implements it, but I think you really need to give the user the option of specifying the field names and not reading/writing headers. It can't be implicit as I interpreted Rob's earlier comment: > NamedTupleRea

[issue1818] Add named tuple reader to CSV module

2009-02-26 Thread Skip Montanaro
Skip Montanaro added the comment: Hrm... I replied twice by email. Only one comment appears to have survived the long trip. Here's my second reply: Rob> NamedTupleReader and NamedTupleWriter should be inverses. This Rob> means that NamedTupleWriter needs to write headers. This shou

[issue1818] Add named tuple reader to CSV module

2009-02-26 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: I think it would be useful to have. ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: h

[issue1818] Add named tuple reader to CSV module

2009-02-26 Thread Skip Montanaro
Skip Montanaro added the comment: Raymond> Barry or Skip, is this something you want in your module? Sorry, I haven't really looked at this ticket other than to notice its presence. I wrote the DictReader/DictWriter functions way back when, so I'm pretty comfortable using them. I haven't felt

[issue1818] Add named tuple reader to CSV module

2009-02-26 Thread Raymond Hettinger
Raymond Hettinger added the comment: The two latest patches (ntreader4.diff and named_tuple_write_header.patch) seem like they are going in the right direction and are getting close. Barry or Skip, is this something you want in your module? -- stage: -> patch review type: -> feature

[issue1818] Add named tuple reader to CSV module

2009-02-25 Thread Rob Renaud
Changes by Rob Renaud : Removed file: http://bugs.python.org/file13187/named_tuple_write_header.patch ___ Python tracker ___ ___ Python-bugs-li

[issue1818] Add named tuple reader to CSV module

2009-02-25 Thread Rob Renaud
Rob Renaud added the comment: My previous patch could write the header twice. But I am not sure about about how the writer should handle the fieldnames parameter on one hand, and the namedtuple._fields on the other. Added file: http://bugs.python.org/file13188/named_tuple_write_header2.patch

[issue1818] Add named tuple reader to CSV module

2009-02-25 Thread Rob Renaud
Rob Renaud added the comment: I am totally new to Python dev. I reinvented a NamedTupleReader tonight, only to find out that it was created a year ago. My primary motivation is that DictReader reads headers nicely, but DictWriter totally sucks at handling them. Consider doing some filtering o

[issue1818] Add named tuple reader to CSV module

2009-02-10 Thread Jervis Whitley
Jervis Whitley added the comment: Updated NamedTupleReader to give a rename=False keyword argument. rename is passed directly to the namedtuple factory function to enable automatic handling of invalid fieldnames. Two new tests for the rename keyword. Cheers, Added file: http://bugs.python.org

[issue1818] Add named tuple reader to CSV module

2009-02-09 Thread Raymond Hettinger
Raymond Hettinger added the comment: In r69480, named tuples gained the ability to automatically rename invalid fieldnames. ___ Python tracker ___

[issue1818] Add named tuple reader to CSV module

2009-02-09 Thread Raymond Hettinger
Raymond Hettinger added the comment: Consider providing a hook to a function that converts non-conforming field names (ones with a leading underscore, leading digit, non-letter, keyword, or duplicate name). class NamedTupleReader: def __init__(self, f, fieldnames=None, restkey=None, restval

[issue1818] Add named tuple reader to CSV module

2009-02-09 Thread Jervis Whitley
Jervis Whitley added the comment: An implementation of a namedtuple reader and writer. Created a writer for the case where user would like to specify desired field names and default values on missing field names. e.g. mywriter = NamedTupleWriter(f, fieldnames=['f1', 'f2', 'f3'],

[issue1818] Add named tuple reader to CSV module

2008-01-22 Thread Skip Montanaro
Skip Montanaro added the comment: I'd personally be kind of surprised if Barry had any thoughts on this. Is there any reason this couldn't be pushed down into the C code and replace the normal tuple output completely? In the absence of any fieldnames you could just dream some up, like "field001"

[issue1818] Add named tuple reader to CSV module

2008-01-22 Thread Raymond Hettinger
Raymond Hettinger added the comment: Barry, any thoughts on this? __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs-list mailing list Unsubscribe: http

[issue1818] Add named tuple reader to CSV module

2008-01-13 Thread Raymond Hettinger
New submission from Raymond Hettinger: Here's a proof-of-concept patch. If approved, will change from generator form to match the other readers and will add a test suite. The idea corresponds to what is currently done by the dict reader but returns a space and time efficient named tuple instead