help I'm getting delimited

aka alexoplocatie at
Wed Dec 17 15:28:01 CET 2008

Hi John, thanks.
You're right, I didn't past the method header because I thought it
didn't matter when the input filename is hardcoded.
The try/except isn't very helpful indeed so I commented it out.
You're right I wrongly referred to the UnicodeReader
class in my first post because that's ultimately where I want to go
I outcommented it here for you to see.
The fact is that neither csv.reader nor the UnicodeReader will read
the file, while writing with the UnicodeWriter
works like a charm.
That's why I put str() around roles to see any content.
I simplified the csv-file by cutting off columns without result. The
file looks now like:


The dictionary on the return is because this code is part of my
TurboGears application.
The entire method is:

import csv
from utilities.urw       import UnicodeWriter, UnicodeReader

    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:
        ## except:
            ## msg = "Something's wrong with the csv.reader"
        return dict(filepath=inp,

csv.reader results in: for r in reader: Error: line contains NULL

Use of UnicodeReader results in: UnicodeDecodeError: 'utf8' codec
can't decode byte 0xff in position 0: unexpected code byte

Will post only complete code from now on thanks.

More information about the Python-list mailing list