0

How do I translate the following VBScript code in Field Calculator to Python using the Python-parser?

Function FindLabel ( [MHUNIT], [BLDG_NUM] )
 If Not IsNull( [MHUNIT] ) Then
  FindLabel = [MHUNIT]
 Else
  FindLabel = [BLDG_NUM]
 End If
End Function
  • 1
    Perhaps you could show us what you have tried? – Barbarossa Mar 10 '17 at 15:26
  • 1
    A question asking how to do something in code should always include a code attempt showing what you've tried and detailing where you are stuck. Is there a reason you need to change your labels from VBS to Python? – Midavalo Mar 10 '17 at 15:40
  • 1
    That code looks like it comes from a label expression not from the field calculator. – PolyGeo Mar 10 '17 at 20:28
1

This should do what you want:

def FindLabel([MHUNIT], [BLDG_NUM]):
    if [MHUNIT]:
        return [MHUNIT]
    else:
        return [BLDG_NUM]

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.