I am trying to use an inline if - else statement in an exported python script. (Arc10.1, python 2.7)
Here is sample data:
OBJECTID CODE TYPE
1 R <null>
2 S <null>
3 R <null>
4 D <null>
What I want:
OBJECTID CODE TYPE
1 R River
2 S Not River
3 R River
4 D Not River
possible code that does not work:
import arcpy
arcpy.env.workspace=r"C:\temp\geodatabase.gdb"
arcpy.CalculateField_management("Water_Linear", "TYPE", "'River'" if '!CODE!' == 'R" else "'Not River'", "PYTHON")
I think I have a syntax problem in my expression, but not sure. Can this be done, or do I have to use code blocks? Does anyone know limits of inline Python 'if' statements? Can I expand upon 'if'-'else', and add some 'elif' parameters?
Here is sample data:
OBJECTID CODE TYPE
1 R <null>
2 S <null>
3 R <null>
4 D <null>
What I want:
OBJECTID CODE TYPE
1 R River
2 S Not River
3 R River
4 D Not River
possible code that does not work:
import arcpy
arcpy.env.workspace=r"C:\temp\geodatabase.gdb"
arcpy.CalculateField_management("Water_Linear", "TYPE", "'River'" if '!CODE!' == 'R" else "'Not River'", "PYTHON")
I think I have a syntax problem in my expression, but not sure. Can this be done, or do I have to use code blocks? Does anyone know limits of inline Python 'if' statements? Can I expand upon 'if'-'else', and add some 'elif' parameters?