Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

iteration question - replace string

$
0
0
Hello,
I was wondering if somebody might be able to shed some light on what I'm doing wrong here. I have a file geodatabase with some tables in it. I want the script to iterate through each of the tables, look in one specific field ("PHOTO1"), and then look at the existing URL path that is there in the field, and do a replace on the string. Where it sees "\Photo\", it will change it to "_Patrol\Photo\".

It seems like what I have should work, yet I get an error that says "TypeError: 'NoneType' object is not iterable". Any ideas?

Code:

import arcpy
arcpy.env.workspace = "C:\Users\jp8439\Desktop\temp.gdb"
tableList = arcpy.ListTables()                                        #list the tables in the geodatabase
for table in tableList:                                                    #iterate the tables
    cursor = arcpy.UpdateCursor(table)                            #place update cursor in the first table
    for row in cursor:         
        str = row.getValue("PHOTO1")                                  #get string value in PHOTO1 field
        rep = str.replace("\\Photos\\", "_Patrol\\Photos\\")      #variable to replace "photos" with "_patrol\photos"
        row.setValue("PHOTO1", rep)                                  # do the replace
        cursor.updateRow(row)
del cursor, row


Viewing all articles
Browse latest Browse all 2485

Trending Articles