def update(field): if field[0] in str(range(0, 9)) or field[0] == '#': pass else: return field
update(!TAG!)
# 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
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 integer
But 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
Thank you, that worked partially, this is what is left:
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.