ArcPy/Python: How can I add a word into a string infront of a specific word of that string? -


i'm working arcpy edit large shapefiles. i'm using updatecursor function find , update type attribute based on feature's name. in case, changing buoys lighted buoys based on words light, or lighted being in features name. basic block using follows.

cursor = arcpy.updatecursor(navp,"""typec = 'lateral buoy' , name like'%lighted%' or name like'%light%'""") row in cursor:     row.setvalue('typec',"lateral lighted buoy")     cursor.updaterow(row) 

the issue have every type of buoy in data. have on dozen colors, lateral, , non lateral buoys deal with. know repeat block each 1 of cases , workable script, messy, , i'm trying learn how make code more elegant, , efficient. there ways drop "lighted" in front of buoy features selected by
cursor = arcpy.updatecursor(navp,"""typec like'%buoy%' , name like'%lighted%' or name like'%light%'""")??

thanks help.

so solved own issue. had review built in string formatting functions. used .replace() inside .updatecursor loop find, , replace appropriate sub strings. here final code block.

cursor = arcpy.updatecursor(navp,"""typec like'%buoy%' , name like'%light%'""") row in cursor:     row.setvalue('typec',row.getvalue("typec").replace("buoy","lighted buoy"))     cursor.updaterow(row)  del cursor 

short , sweet. looking!


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -