delineating by comma where commas inside quotation marks don't count

Junior mlongjr at verizon.net
Sat Oct 27 06:55:03 CEST 2007


"Dan Bishop" <danb_83 at yahoo.com> wrote in message 
news:1193278225.923337.217160 at k35g2000prh.googlegroups.com...
> On Oct 24, 8:56 pm, "Junior" <mlon... at verizon.net> 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.
Thanks for the help! I used the csv module to write this;

import csv
reader = csv.reader(open('testfile.txt', "rb"))
for row in reader:
    print "var2= ", row[2]


The reason I didn't use the csv module is because I read this book to learn
Python,

Python Programming for the Absolute Beginner, Second Edition (For the
Absolute Beginner)
by Michael Dawson (Author),

and it did not mention the csv module it just explained how to import
modules. I also read

the tutorial that comes with python but it ends with the History and License
section.

Can you recommend a book that explains the most used modules?






More information about the Python-list mailing list