help I'm getting delimited

aka alexoplocatie at gmail.com
Wed Dec 17 11:30:02 CET 2008


Due to being in a hurry I didn't paste correctly so I lost the try
clause (sorry).
The intention is to parse a csv file and (ultimately) put values of
column 1 ("id") in a list (so I need to append in the loop) that will
be used to fill a session var.
The complete code is:

roles = []
inp = 'C:/temp/test.csv'
try:
    fp = open(inp, 'rb')
    reader = csv.reader(fp, dialect='excel', delimiter=';')
    for r in reader:
        roles.append(r)   ## ultimately should be something like r.id
or r[0]
except:
    msg = 'Something's wrong with the csv.reader'
return dict(file=inp,roles=str(roles))

The roles list isn't populated at all :(



More information about the Python-list mailing list