On 10/24/07, Dan Bishop <[EMAIL PROTECTED]> wrote: > > On Oct 24, 8:56 pm, "Junior" <[EMAIL PROTECTED]> wrote: > > I want to open a text file for reading and delineate it by comma. I > also > > want any data > > surrounded by quotation marks that has a comma in it, not to count the > > commas inside the > > quotation marks > > Use the csv module. > > -- >
The csv module is definitely the way to go here as it knows how to handle commas within text qualifiers (double quotes). Do something like this: import csv reader = csv.reader(open('testfile.txt')) for ct,row in enumerate(reader): print "var2=", row[2] if ct>2: break The comma separated list parser in pyparsing is also great for this, particularly when the input gets dirtier: http://pyparsing.wikispaces.com/space/showimage/commasep.py -- Travis Brady http://travisbrady.com/
-- http://mail.python.org/mailman/listinfo/python-list