Re: There must be a better way

2013-04-23 Thread Neil Cerutti
On 2013-04-22, Colin J. Williams c...@ncf.ca wrote: Since I'm only interested in one or two columns, the simpler approach is probably better. Here's a sketch of how one of my projects handles that situation. I think the index variables are invaluable documentation, and make it a bit more

Re: There must be a better way

2013-04-23 Thread Oscar Benjamin
On 23 April 2013 14:36, Neil Cerutti ne...@norwich.edu wrote: On 2013-04-22, Colin J. Williams c...@ncf.ca wrote: Since I'm only interested in one or two columns, the simpler approach is probably better. Here's a sketch of how one of my projects handles that situation. I think the index

Re: There must be a better way

2013-04-23 Thread Tim Chase
On 2013-04-23 13:36, Neil Cerutti wrote: On 2013-04-22, Colin J. Williams c...@ncf.ca wrote: Since I'm only interested in one or two columns, the simpler approach is probably better. Here's a sketch of how one of my projects handles that situation. I think the index variables are

Re: There must be a better way

2013-04-23 Thread Skip Montanaro
But a csv.DictReader might still be more efficient. Depends on what efficiency you care about. The DictReader class is implemented in Python, and builds a dict for every row. It will never be more efficient CPU-wise than instantiating the csv.reader type directly and only doing what you need.

Re: There must be a better way (correction)

2013-04-23 Thread Tim Chase
On 2013-04-23 09:30, Tim Chase wrote: But a csv.DictReader might still be more efficient. I never tested. This is the only place I've used this optimization. It's fast enough. ;) I believe the csv module does all the work at c-level, rather than as pure Python, so it should be notably

Re: There must be a better way

2013-04-22 Thread Oscar Benjamin
On 21 April 2013 14:15, Colin J. Williams c...@ncf.ca wrote: In the end, I used: inData= csv.reader(inFile) def main(): if ver == '2': headerLine= inData.next() else: headerLine= inData.__next__() ... for item in inData: assert len(dataStore) ==

Re: There must be a better way

2013-04-22 Thread Neil Cerutti
On 2013-04-21, Colin J. Williams c...@ncf.ca wrote: On 20/04/2013 9:07 PM, Terry Jan Reedy wrote: On 4/20/2013 8:34 PM, Tim Chase wrote: In 2.x, the csv.reader() class (and csv.DictReader() class) offered a .next() method that is absent in 3.x In Py 3, .next was renamed to .__next__ for

Re: There must be a better way

2013-04-22 Thread Colin J. Williams
On 22/04/2013 10:42 AM, Neil Cerutti wrote: On 2013-04-21, Colin J. Williams c...@ncf.ca wrote: On 20/04/2013 9:07 PM, Terry Jan Reedy wrote: On 4/20/2013 8:34 PM, Tim Chase wrote: In 2.x, the csv.reader() class (and csv.DictReader() class) offered a .next() method that is absent in 3.x In

Re: There must be a better way

2013-04-21 Thread Colin J. Williams
On 20/04/2013 9:07 PM, Terry Jan Reedy wrote: On 4/20/2013 8:34 PM, Tim Chase wrote: In 2.x, the csv.reader() class (and csv.DictReader() class) offered a .next() method that is absent in 3.x In Py 3, .next was renamed to .__next__ for *all* iterators. The intention is that one iterate with

Re: There must be a better way

2013-04-21 Thread Jussi Piitulainen
Colin J. Williams writes: ... It is not usual to have a name with preceding and following udserscores,imn user code. Presumably, there is a rationale for the change from csv.reader.next to csv.reader.__next__. ... I think the user code is supposed to be next(csv.reader). For example,

Re: There must be a better way

2013-04-21 Thread Peter Otten
Colin J. Williams wrote: I was seeking some code that would be acceptable to both Python 2.7 and 3.3. In the end, I used: inData= csv.reader(inFile) def main(): if ver == '2': headerLine= inData.next() else: headerLine= inData.__next__() ... I

Re: There must be a better way

2013-04-21 Thread Colin J. Williams
On 21/04/2013 9:39 AM, Jussi Piitulainen wrote: Colin J. Williams writes: ... It is not usual to have a name with preceding and following udserscores,imn user code. Presumably, there is a rationale for the change from csv.reader.next to csv.reader.__next__. ... I think the user code is

Re: There must be a better way

2013-04-21 Thread Colin J. Williams
On 21/04/2013 9:43 AM, Peter Otten wrote: Colin J. Williams wrote: I was seeking some code that would be acceptable to both Python 2.7 and 3.3. In the end, I used: inData= csv.reader(inFile) def main(): if ver == '2': headerLine= inData.next() else:

Re: There must be a better way

2013-04-20 Thread Chris Rebert
On Sat, Apr 20, 2013 at 4:46 PM, Colin J. Williams c...@ncf.ca wrote: Below is part of a script which shows the changes made to permit the script to run on either Python 2.7 or Python 3.2. I was surprised to see that the CSV next method is no longer available. Suggestions welcome. snip

Re: There must be a better way

2013-04-20 Thread Steven D'Aprano
On Sat, 20 Apr 2013 19:46:07 -0400, Colin J. Williams wrote: Below is part of a script which shows the changes made to permit the script to run on either Python 2.7 or Python 3.2. I was surprised to see that the CSV next method is no longer available. This makes no sense. What's the CSV

Re: There must be a better way

2013-04-20 Thread Tim Chase
On 2013-04-21 00:06, Steven D'Aprano wrote: On Sat, 20 Apr 2013 19:46:07 -0400, Colin J. Williams wrote: Below is part of a script which shows the changes made to permit the script to run on either Python 2.7 or Python 3.2. I was surprised to see that the CSV next method is no longer

Re: There must be a better way

2013-04-20 Thread Terry Jan Reedy
On 4/20/2013 8:34 PM, Tim Chase wrote: In 2.x, the csv.reader() class (and csv.DictReader() class) offered a .next() method that is absent in 3.x In Py 3, .next was renamed to .__next__ for *all* iterators. The intention is that one iterate with for item in iterable or use builtin functions