Select to view content in your preferred language

Regex assist needed

1132
8
Jump to solution
07-28-2014 01:16 PM
JustinWhisenant
Emerging Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
IanMurray
Honored Contributor

you probably need this after row[0] = goodtext

rows.updateRow(row)

ArcGIS Help (10.2, 10.2.1, and 10.2.2)

View solution in original post

0 Kudos
8 Replies
IanMurray
Honored Contributor

you probably need this after row[0] = goodtext

rows.updateRow(row)

ArcGIS Help (10.2, 10.2.1, and 10.2.2)

0 Kudos
JustinWhisenant
Emerging Contributor

Ian,

Thank you that was the problem.  I forgot to apply the update.  It seems obvious now.

Justin

0 Kudos
AnthonyGiles
Honored Contributor

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:

ArcGIS Desktop

ArcGIS Help 10.1

0 Kudos
IanMurray
Honored Contributor

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.

AnthonyGiles
Honored Contributor

Cheers Ian,

i have just read this help and what you are saying makes sense:

ArcGIS Help 10.1

0 Kudos
IanMurray
Honored Contributor

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.

0 Kudos
AnthonyGiles
Honored Contributor

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

0 Kudos
IanMurray
Honored Contributor

I don't see why it wouldn't, I've never tested it but I would assume it would work.

0 Kudos