1

I wrote a script for ArcMap using python that would take a table with unsupported characters, Romanize or transliterate those applicable fields, and create a shapefile with any geographic information that might also be contained in the table. The rest of the code I have determined is working alright. My main problem is the ability to search letter by letter within each row of the input table, which I had working earlier but I guess I reverted to an earlier error.

# Loop through each row in the copied table and replacing each cell with one based on the reference table.
rows = access.SearchCursor(outtable, orfield) # Creates a search cursor that looks in the outtable for what is in the native language field.
row = rows.next() # Establishes a variable that cycles row to row.

while row: # Beginning of "while" loop.
    for r in row: # Searches each letter within the searched row.
        for o in orfield: # Searches each cell based on the searched field from the reference table.
            if r == o: # If/Else statement for seeing if the letter being searched for in the intable (r) is identical to the letter in the orthography field (o).
                r.replace(orfield, profield) # Replaces any identical letters with the associated pronunciation.
            else:
                row.next() # Cycles to the next row.

I feel like I'm missing something but not quite sure. If you need me to elaborate more on what else is contained in my script, let me know. Don't necessarily need to write the script for me but if there's a module or function that I could you, let me know what it is and where I can read about it.

RWhitacre
  • 11
  • 2

1 Answers1

0

A little fuzzy on some of your details but it appears the code is attempting to compare a Field data object (created w/for r in row) with the elements in some input set, which you seem to imply is a string. Aside from the type mismatch of Field vs string, I believe that a Row object is not iterable the way you've written it. You can get the fields with something like:

fldList = list()
for fld in arcpy.ListFields(r'C:\Workspace\somedata.shp'): 
    fldList.append(fld.name)

and then iterate of fldList using something like:

for fld in fldList:
     fldValue = row.getValue(fld)
     ....do some regex/string parsing
     ....if condition met, use row.setValue(fld, newValue) and rows.update(row)
Roland
  • 499
  • 6
  • 16