With arcpy I made a script to get the properties of the featureclasses and tables in Esri geodatabases (.gdb), and the properties of its fields. Simple script and it always has run well.
But now a fieldname happens to have the character € in it (fieldname = 'Budget_€') and the script crashes with the message 'UnicodeEncodeError: 'ascii' codec can't encode character u'\u20ac' in position 59: ordinal not in range(128)'.
Yes, a coding issue, and it shouldn't be that difficult to solve. But all I tried fails with the same message.
What I tried and crashes:
# -*- coding: utf-8 -*- (also tried # -*- coding: cp1252 -*-)
import codecs
< code >
for field in fieldLst:
f.write(gdbbasefolder+"\t"+gdbname+"\t"+table+"\t"+ field.name+"\t"+ field.type+"\t"+ str(field.length)+"\t"+shapeType +"\t"+str(factoryCode) +"\t"+hasZ +"\t"+hasM +"\t"+ hasSpatialIndex+"\t"+ str(recs))
in which 'field.name' gives the problems.
I also tried:
field.name.encode('utf-8')
field.name.decode('utf-8')
but it keeps crashing.
Using Python 2.7.14, running in IDLE 2.7.14.
Read several threads about this, but nothing helps.
What should I do?