I've got a point feature class of road intersections in which I used a script to create a field of joined road names from a line feature class. I've got to separate each road name into separate fields. I've been able to do that without much problem. But the road names were joined in more or less random fashion and now I need to rank the road names based on their type into their own field i.e. Interstates in the first field, US Highways in the second, state highways in the third, etc. All the highways begin with either Interstate, US or State.
I've tried doing a wildcard if ... else on the list created by the .split inside the update cursor but apparently that's not allowed. From searching it seems that regular expressions (which I've never used) might be my only hope. Anybody have any suggestions?
The code I used to split the field and place the road names into individual fields.
try: # Import arcpy module from arcpy import env #set workspace env.workspace = r"GDB" # Local variables: fc = r"feature class" #create update cursor to place values in fields fieldList = ["AllRoutes","ID_Road1_Cross","ID_Road2_Cross","ID_Road3_Cross", "ID_Road4_Cross","ID_Road5_Cross"] with arcpy.da.UpdateCursor(fc,fieldList) as cursor: for row in cursor: cleaned = [x.strip() for x in row.split("&")] if len(cleaned) == 2: row = cleaned row = cleaned elif len(cleaned) == 3: row = cleaned row = cleaned row = cleaned elif len(cleaned) == 4: row = cleaned row = cleaned row = cleaned row = cleaned elif len(cleaned) == 5: row = cleaned row = cleaned row = cleaned row = cleaned row = cleaned cursor.updateRow(row) except arcpy.ExecuteError: print arcpy.GetMessage(2) except: print "Process did not complete"