namdoogttam

Help with Python please!? (Questions from a rookie)

Discussion created by namdoogttam on May 6, 2013
Latest reply on May 6, 2013 by jskinner-esristaff
I'm do not know much of anything about python and I'm looking for some help converting a VBA expression that I am trying to use in ArcMap's Field Calculator (NOTE: I can't get this VBA to work either, but hopefully it will convey to you what I am trying to accomplish). In Field Calculator, here is what I'm entering in the codeblock:

Dim blah
If [STNAME] like "* [A-Z][A-Z]" then
blah = RIGHT ([STNAME],2)
Elseif [STNAME] like "* [A-Z][A-Z][A-Z]" then
blah = RIGHT ([STNAME],3)
ELSE
blah = ""
End if


Basically the intent is to look at the street name field (STNAME), assess whether it ends with a two or three letter string (i.e. AVE, RD, DR, WAY, CT, CIR, etc.), and parse the appropriate number of characters off into the street type field (STTYPE - the one I'm calculating). (Don't worry: I'll handle the four-character street types (PKWY, BLVD, etc.) and other street name anomolies with a different process).

I would really like to see a working Python version of this code, that actually works, if anyone has suggestions. I was experimenting with some very, very, very basic Python expressions, and couldn't even get [I]them[I/] to work (I must be doing something wrong!):

def Parsed(Street)
  if Street = "13 AVE":
    return "hello world"
  else:
    return ""


Can someone explain the reasoning behind what to enter in the expression block (not the Codeblock) using the Python parser in Field Calculator? I appreciate any tips you can offer.

Outcomes