Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 搜寻及;使用Python逐行、逐字母替换表中的行_Python 2.7_Arcpy_Arcmap - Fatal编程技术网

Python 2.7 搜寻及;使用Python逐行、逐字母替换表中的行

Python 2.7 搜寻及;使用Python逐行、逐字母替换表中的行,python-2.7,arcpy,arcmap,Python 2.7,Arcpy,Arcmap,我使用python为ArcMap编写了一个脚本,该脚本将获取一个包含不受支持字符的表,将这些适用字段罗马化或音译,并创建一个包含表中可能包含的任何地理信息的shapefile。我确定的代码的其余部分工作正常。我的主要问题是能够在输入表的每一行中逐字搜索,这是我之前工作过的,但我想我回到了以前的错误 # Loop through each row in the copied table and replacing each cell with one based on the reference

我使用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.

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

您的一些详细信息有点模糊,但代码似乎试图将字段数据对象(为行中的r创建的w/
)与某些输入集中的元素进行比较,你似乎暗示这是一个字符串。除了字段和字符串的类型不匹配之外,我认为行对象不适合您编写它的方式。您可以通过以下方式获取字段:

fldList = list()
for fld in arcpy.ListFields(r'C:\Workspace\somedata.shp'): 
    fldList.append(fld.name)
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)
然后使用如下方法迭代
fldList

fldList = list()
for fld in arcpy.ListFields(r'C:\Workspace\somedata.shp'): 
    fldList.append(fld.name)
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)