def update(field): if field[0] in str(range(0, 10)) or field[0] == '#': pass else: return field
update(!Label_Field!)
update(!TAG!)
Can you send a screen shot of what you entered in the Field Calculator. It looks like the code did the opposite of what you are looking to accomplish. It calculated all the text values that begin with a number and '#' sign, and not the values that begin with a character.
Thank you, that worked partially, this is what is left:
Use a Regular Expression to match names with letters to make a selection, then just do a copy on selected records. Regular expressions are supported in Python and are a very powerful text manipulation tool.Maybe we could assume that no names start with a digit, so you could reverse the search to look for any integerBut if you didn't, an expression re.match('[A-Za-z ]+',inField) would allow any combination of letters and spaces# pseudocode (not run) for interactive Python window # NOT field calculator (keep that for modelbuilder....) import arcpy import re arcpy.env.workspace = "your_gdb_path" cur = arcpy.UpdateCursor("table1") for row in cur: m = re.match('[0-9]+',row.inField) # matches any value beginning with integer string of digits if not m : # ie not nothing found row.nameCopy = m.string cur.updateRow(row) # must not forget this or doesn't write to file del cur # close cursor # nameCopy is target field, inField is source field
# pseudocode (not run) for interactive Python window # NOT field calculator (keep that for modelbuilder....) import arcpy import re arcpy.env.workspace = "your_gdb_path" cur = arcpy.UpdateCursor("table1") for row in cur: m = re.match('[0-9]+',row.inField) # matches any value beginning with integer string of digits if not m : # ie not nothing found row.nameCopy = m.string cur.updateRow(row) # must not forget this or doesn't write to file del cur # close cursor # nameCopy is target field, inField is source field
def update(field): if field[0] in str(range(0, 9)) or field[0] == '#': pass else: return field
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.