Select to view content in your preferred language

convert VB expression to python

7218
33
02-23-2016 07:32 AM
by Anonymous User
Not applicable

I am new to python.  I am using a model to automate a data update process.  Part of the model is to calculate a new field by concatenating 3 other fields and left trimming to remove white space as needed.  Below is the VB expression.  When I use python to automatically run this model it fails at the expression to calculate the field.   Below is the VB expression.  I cannot find an example of how this would look as a python expression.  Can anyone help?

FullStreet =

LTrim( [LOCN] &" " &  LTrim( [LOCD] & " " &  [LOCS]))

Any help would be greatly appreciated.

Sincerely,

Nita L Hester

0 Kudos
33 Replies
RandyBurton
MVP Alum

Assuming all fields are TEXT, this might work (note the space between the double quotes in line 2):

def processInput(input1, input2, input3):
    return " ".join([str(i).strip() for i in [ !input1!, !input2!, !input3!] if i]).strip()
# you can also tack on .replace("  "," ") after the last .strip() to remove double spaces if needed
by Anonymous User
Not applicable

That worked!!!!!!!!!!

Thanks so much everyone for your assistance and thanks for your patience with a beginner.

Sincerely,

Nita

RandyBurton
MVP Alum

Glad it worked.  It was a group effort.  Check out Some Python Snippets​. It will help you with learning Python.

by Anonymous User
Not applicable

Thanks for the info, I appreciate it.

0 Kudos