I am having problems with the arcpy.ValidateFieldName function in combination with unicode characters. I want to add a field to a shape field. The field name is not allowed to be bigger than 10 bytes (or at least I think so), but ValidateFieldName cuts it off at 10 characters. Since a unicode character is not necessarily one byte big, this causes problems.
Consider these three examples:
#Path to an existing shape file.file = r"C:\path\file.shp"#This works. The name is cut after 10 characters to "abcdefghij"name1 = arcpy.ValidateFieldName("abcdefghijklmnop", file)print name1arcpy.AddField_management(in_table = file, field_name = name1, field_type = "TEXT")#This works. The name is unchanged (since it is less than 10 characters)#ArcMap accepts it since it is not larger than 10 bytes.name2 = arcpy.ValidateFieldName("
أكثر...
Consider these three examples:
#Path to an existing shape file.file = r"C:\path\file.shp"#This works. The name is cut after 10 characters to "abcdefghij"name1 = arcpy.ValidateFieldName("abcdefghijklmnop", file)print name1arcpy.AddField_management(in_table = file, field_name = name1, field_type = "TEXT")#This works. The name is unchanged (since it is less than 10 characters)#ArcMap accepts it since it is not larger than 10 bytes.name2 = arcpy.ValidateFieldName("
أكثر...