I had some VB code in one of my Calculate Field modules in modelbuilder. I am trying to convert it to Python
Can anybody help me with this?
IF RTRIM([PRE_DIR]) = " " then
MyLabel = LTRIM([STR_NAME]) & " " & [SUF_FIX]
MyLabel = RTRIM([PRE_DIR]) & " " & LTRIM(RTRIM([STR_NAME])) & " " & [SUF_FIX]
Solved! Go to Solution.
I know I marked your response as correct and it may be correct but I'm still getting an error when trying to convert my if statement to python. I tried this but it isn't working
If (!PRE_DIR!).RTrim() = " "
print(!STR_NAM!) + " " + (!SUF_FIX!)
print(!PRE_DIR!).RTrim() + " " + LTrim (RTrim(!STR_NAME!)) + " " +
Any help would be appreciated!
Whatever your trying to convert it does not look like it came from Model Builder.
I have used VB code in model builder expressions in the past and if they work in model builder, which I am assuming yours do, they should convert to python and the code from your last post is not python. Or are you just posting the original VB code.
I know I have the syntax wrong because I am very unfamiliar with python syntax. I have just been looking at python examples on the internet and doing what I thought would work since what I had in VB works. Here is a screenshot of the Calculate Field module I have in python.
# Process: Calculate Field (2)
arcpy.CalculateField_management(clines__5_, "LABEL", "RTRIM([PRE_DIR]) & \" \" & LTRIM(RTRIM([STR_NAME])) & \" \" & [SUF_FIX]", "VB", "IF RTRIM([PRE_DIR]) = \" \" then\\n MyLabel = LTRIM([STR_NAME]) & \" \" & [SUF_FIX]\\nelse\\n