AnsweredAssumed Answered

Write Russian field names to txt

Question asked by K0831901 on May 20, 2014
Latest reply on May 20, 2014 by K0831901
I am trying to script a process to write out a list of datasets > feature classes > fields to a txt file but I am getting:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-8: ordinal not in range(128) when the script gets to the bit to print out the field names. I think this is because some of the field names are in Russian cyrillic.

Can anyone advise how I get these Russian names to print to my text file? I have gathered that it is something to do with unicode but I'm finding the literature on unicode a bit daunting! My code is as follows:

... for fd in fdList: ...     arcpy.env.workspace = wksp+'/'+fd ...     fcList = arcpy.ListFeatureClasses() ...     txtFile.write (fd) ...     txtFile.write(os.linesep) ...     for fc in fcList: ...         arcpy.env.workspace = wksp+'/'+fd+'/'+fc ...         fields = arcpy.ListFields(arcpy.env.workspace) ...         txtFile.write(' '+fc) ...         txtFile.write(os.linesep) ...         for field in fields: ...             fieldname = ...             txtFile.write(fieldname) ...             txtFile.write(os.linesep) ... #close file ... txtFile.close() ... print "done"

Many thanks,