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
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
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
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
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
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
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
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
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