I am trying to remove "/1" from the end of every entry in a certain field. I know I can just strip it off, but I would like to solve it with regex for my own edification. Here is my code so far. It runs without error but has no effect on the data.
with arcpy.da.UpdateCursor("Table", "parcel_ID") as rows:
... for row in rows:
... badtext=row[0]
... goodtext=re.sub(r'/1', '', badtext)
... row[0]=goodtext
Anyone know what I am doing wrong? Thanks.
Solved! Go to Solution.
you probably need this after row[0] = goodtext
rows.updateRow(row)
you probably need this after row[0] = goodtext
rows.updateRow(row)
Ian,
Thank you that was the problem. I forgot to apply the update. It seems obvious now.
Justin
Justin,
you are looping through the rows but you are not looping through your fields and assigning any data to a particular field. Have a look at some of these examples:
Anthony, he is calling the value of one field he is accessing with cursor with his index. You posted help for the old cursor, not the data access cursor, for which his syntax should be fine, since it takes a feature class name, and field(s) which he has(assuming his feature is called "Table")
He isn't looping through multiple fields, just the one field.
tbh, I posted the wrong help the first time too and had to go correct myself, its easy to get the regular and data access cursors mixed up.
Ian,
will python in arcmap recognise the \Z metacharacter to ensure only the end of the string is changed and not any occurrences in the rest of the text
I don't see why it wouldn't, I've never tested it but I would assume it would work.