Re: Python's CSV reader

2005-08-08 Thread Peter Otten
Stephan wrote: > DictReader field names on the fly. Here is a rudimentary example of my > working code and the data it can parse. > > - > John|Smith > Beef|Potatos|Dinner Roll|Ice Cream > Susan|Jones > Chicken|Peas|Biscuits|Cake > Roger|Miller > Pork|Salad|Muf

Re: Python's CSV reader

2005-08-07 Thread Stephan
Andrew McLean wrote: > You are welcome. One point. I think there have been at least two > different interpretations of precisely what you task is. > > I had assumed that all the different "header" lines contained data for > the same fields in the same order, and similarly that all the "detail" > l

Re: Python's CSV reader

2005-08-05 Thread Andrew McLean
In article <[EMAIL PROTECTED]>, Stephan <[EMAIL PROTECTED]> writes >Thank you all for these interesting examples and methods! You are welcome. One point. I think there have been at least two different interpretations of precisely what you task is. I had assumed that all the different "header" l

Re: Python's CSV reader

2005-08-04 Thread Peter Otten
Stephan wrote: > Thank you all for these interesting examples and methods! You're welcome. > Supposing I want to use DictReader to bring in the CSV lines and tie > them to field names, (again, with alternating lines having different > fields), should I use two two DictReaders as in Christopher's

Re: Python's CSV reader

2005-08-04 Thread Stephan
Thank you all for these interesting examples and methods! Supposing I want to use DictReader to bring in the CSV lines and tie them to field names, (again, with alternating lines having different fields), should I use two two DictReaders as in Christopher's example or is there a better way? -- St

Re: Python's CSV reader

2005-08-04 Thread Andrew McLean
In article <[EMAIL PROTECTED]>, Stephan <[EMAIL PROTECTED]> writes >I'm fairly new to python and am working on parsing some delimited text >files. I noticed that there's a nice CSV reading/writing module >included in the libraries. > >My data files however, are odd in that they are composed of lin

Re: Python's CSV reader

2005-08-04 Thread Peter Otten
Stephan wrote: > Can the CSV module be coerced to read two line formats at once or am I > better off using read and split? Yes, it can: import csv import sys reader = csv.reader(sys.stdin) while True: try: names = reader.next() values = reader.next() except StopIteratio

Re: Python's CSV reader

2005-08-03 Thread Christopher Subich
Stephan wrote: > Can the CSV module be coerced to read two line formats at once or am I > better off using read and split? Well, readlines/split really isn't bad. So long as the file fits comfortably in memory: fi = open(file) lines = fi.readlines() evens = iter(lines[0::2]) odds = iter(lines[1

Python's CSV reader

2005-08-03 Thread Stephan
I'm fairly new to python and am working on parsing some delimited text files. I noticed that there's a nice CSV reading/writing module included in the libraries. My data files however, are odd in that they are composed of lines with alternating formats. (Essentially the rows are a header record a