1

Here is my current expression:

def FindLabel ( [FULL_NAME] ):
fn = [FULL_NAME]
if "COUNTY ROAD" in fn:
 return  "CR " + fn[11:]
elif "% COUNTY ROAD" in fn:
 return fn[:1] + "CR" + fn[13:]
else:
 return fn

This is a valid expression but the line - elif "% COUNTY ROAD" in fn: return fn[:1] + "CR" + fn[13:] isn't working. Some county roads have a pre directional (i.e. E or W) then COUNTY ROAD XXXX. I am trying to return that pre-directional with % wildcard if it exists in the FULL_NAME field.

Is this not correct?

  • The % symbol is a SQL wildcard, not Python. Python doesn't have wildcards (ignoring glob and re modules). – user2856 Mar 5 '16 at 9:02
2

It looks like all you want to do is replace 'COUNTRY ROAD' with 'CR'.

You can use str.replace() to do that.

def find_label(full_name):
   return full_name.replace('COUNTRY ROAD', 'CR')
  • Correct, but how would I account for "W COUNTY ROAD 3066" to label as "W CR 3066"? – Trevor Mar 4 '16 at 18:42
  • Nevermind, that str.replace() covers everything. Thanks! – Trevor Mar 4 '16 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.