Does someone have a code example?
Right solution is:
lyrname.decode('utf-8')
If I use
lyrname.encode('utf-8')
This leads to:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3: ordinal not in range(128)
???
This:
import arcpy import os mxd = arcpy.mapping.MapDocument("CURRENT") for lyr in arcpy.mapping.ListLayers(mxd): if lyr.supports("DATASOURCE"): arcpy.AddMessage("Layer: " + lyr.name + " Source: " + lyr.dataSource) for lyr in arcpy.mapping.ListLayers(mxd): lyrname = str(lyr.name) print lyrname lyrname_replaced = lyrname.replace(" ","_") lyr.name = lyrname_replaced arcpy.AddMessage(lyrname_replaced) arcpy.RefreshTOC()
leads to this error:
File "R:\Karto\zGIS\Python\RenameLayerinMxd.py", line 16, in <module>
lyrname = str(lyr.name)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 3: ordinal not in range(128)
Any ideas?
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.