help I'm getting delimited

aka alexoplocatie at gmail.com
Wed Dec 17 11:15:37 EST 2008


John, this is the actual code I ran in TurboGears which is a Python
framework.
I should have left away the import statements. Trust me, the problem
isn't in there because the UnicodeWriter is functioning perfectly.
I did allready sanitate the csv file to these four lines in Notepad so
there isn't anything more than this:

id;company;department
12;Cadillac;Research
11;Ford;Accounting
10;Chrysler;Sales

The only possible problematic lines are marked ##### here:

> >     def import_roles(self, input=None, *args, **kwargs):
> >         inp = 'C:/temp/test.csv'
> >         roles = []
> >         msg = ''
> >         ## try:
> >         fp = open(inp, 'rb') #####
> >         reader = csv.reader(fp, dialect='excel', delimiter=';') #####
> >         ## reader = UnicodeReader(fp, dialect='excel', delimiter=';') #####
> >         for r in reader:
> >             roles.append(r[0]) #####
> >         fp.close()
> >         ## except:
> >             ## msg = "Something's wrong with the csv.reader"
> >         return dict(filepath=inp,
> >                     roles=str(roles),
> >                     msg=msg)

Yeah rdmur, I'll have a look at the Python commandline.



More information about the Python-list mailing list