1

我使用 python 为 ArcMap 编写了一个脚本,该脚本将获取一个包含不受支持的字符的表格,对这些适用的字段进行罗马化或音译,并创建一个带有任何可能包含在表格中的地理信息的 shapefile。我确定的其余代码工作正常。我的主要问题是能够在输入表的每一行中逐字母搜索,这是我之前工作过的,但我想我恢复到了之前的错误。

# 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.

我觉得我错过了一些东西,但不太确定。如果您需要我详细说明我的脚本中包含的其他内容,请告诉我。不一定需要为我编写脚本,但如果有一个模块或功能我可以,请告诉我它是什么以及我可以在哪里阅读它。

4

1 回答 1

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)
于 2013-09-06T17:38:40.460 回答