Select to view content in your preferred language

iteration question - replace string

987
1
02-25-2014 08:48 AM
JoelThomas
New Contributor II
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?

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 
Tags (2)
0 Kudos
1 Reply
JoelThomas
New Contributor II
Nevermind, the workspace just needed double backslashes in the path
0 Kudos