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'
lstflds=arcpy.ListFields(input)
with open(file,"rb+") as f:
reader=csv.reader(f)
writer = csv.writer(f)
mydict = collections.defaultdict(list)
domains=arcpy.da.ListDomains(workspace)
for domain in domains:
if domain.type =='Text':
coded_values=domain.codedValues
for code,desc in coded_values.iteritems():
mydict[domain.name].append(code)
dict_dom={}
for fld in lstflds:
for dom,values in mydict.iteritems():
if fld.domain==str(dom):
dict_dom.update({fld.name:values})
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))
row[3]=v
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 errorAs 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?