On Jun 12, 8:51 am, infidel <[EMAIL PROTECTED]> wrote:
> # reading CSV files, tuple-unpacking
> import csv
>
> #pacific.csv contains:
> #1,CA,California
> #2,AK,Alaska
> #3,OR,Oregon
> #4,WA,Washington
> #5,HI,Hawaii
>
> reader = csv.reader(open('pacific.csv'))

For generality and portability, this should be:
reader = csv.reader(open('pacific.csv', 'rb'))

> for id, abbr, name in reader:
>     print '%s is abbreviated: "%s"' % (name, abbr)

and this example doesn't demonstrate why one should use the csv module
instead of:
for line in open('pacific.csv'):
   id, abbr, name = line.rstrip().split(',')
   # etc
which is quite adequate for the simplistic example file.


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to