AnsweredAssumed Answered

Issue with line containing NULL byte

Question asked by FLBB on May 4, 2015
Latest reply on May 5, 2015 by FLBB

The script I currently have reads an existing csv and updates(writes to) the csv by refencing a feature class, its attribute fields, and associated domains from a GDB and then updates the domain values with the corresponding attribute field n

ames, in the spreadsheet(csv).


import arcpy,collections,re,csv
arcpy.env.overwriteOutput = True
workspace= 'path to GDB'
file = 'path to csv'
input= 'path to feature class'
with open(file,"rb+") as f:
    writer = csv.writer(f)
    mydict = collections.defaultdict(list)
    for domain in domains:
        if domain.type =='Text':
            for code,desc in coded_values.iteritems():
    for fld in lstflds:
        for dom,values in mydict.iteritems():
            if fld.domain==str(dom):
    print dict_dom
    for row in reader:
        for key,val in dict_dom.items():
            if row[1]==key:
                char_removal = ["[","'","u"," ","]"]
                rx = '[' + re.escape(''.join(char_removal)) + ']'
                v=re.sub(rx,'', str(val))
                print row[3] # This lists the domain codes just fine as they would be written to the spreadsheet
                writer.writerow(row) # This is where the script returns the NULL error


As the last 2 commented lines in the script indicate, there is some kind of a "null byte" error in the writer. I have tried my best to remove any whitespaces/spaces.

How can this be fixed?