1

So I have a spreadsheet that I'm trying to import into a GDB as a shapefile and then modify some fields with arcpy.AlterField_management(). The problem is that the field name has an accent mark (Dirección), and PyScripter says it can't find that field, even if I put # -- coding: utf-8 -- at the beginning of the script. I know the problem is the accent mark, because if I manually remove the accent mark in the original excel file, the script runs with no errors, but as soon as it has the accent mark, it says it can't find that field. Removing it manually is not an option because I want to use this for spreadsheets that have many accent marks and it would take forever to remove all of them manually. I already tried writing utf-8 at the beginning of the script and it still doesn't work and I don't know why. Do you know how can I solve this problem?

This is the line that gets the error: arcpy.AlterField_management("Tabla", "Dirección", "STNAME", "STNAME")

9
  • 3
    It is not possible to "import into a GDB as a shapefile ". It is either a shapefile or a feature class in a geodatabase. – BERA Mar 20 '18 at 10:45
  • You could try: arcpy.AlterField_management("Tabla", [f.name for f in arcpy.ListFields("Tabla") if f.name.startswith('Direcci')][0], "STNAME", "STNAME") – BERA Mar 20 '18 at 10:49
  • 1
    I assume you are running Python 2.7 (ArcGIS Desktop). I assume you are getting an ascii conversion error. You need to prefix the "Dirección" with the u so it will be u"Dirección". More info about unicode docs.python.org/2/howto/unicode.html – Alex Tereshenkov Mar 20 '18 at 11:33
  • 1
    A "shapefile in a geodatabase" is not possible either. A "table is a geodatabase" is possible, provided that it has a legal name (leading alpha, remaining alphanumeric or underscore); one slash or backslash is permitted to denote a parent feature dataset. Any attempt to place a shapefile in a FGDB will fail, regardless of the accents in fieldnames. – Vince Mar 20 '18 at 11:40
  • 1
    @A.T., I think it is a good time to provide more details in the body text to show all the code you have as well as a screenshot with the feature class attribute table you store in the geodatabase. We would like to see what do you have there. A helpful tool for this would be arcpy.ListFields to print all columns you have in the feature class Tabla – Alex Tereshenkov Mar 20 '18 at 13:23