Has anybody ran into in issue where Python field calculations and/or scripts won't properly query Null (None) values? Examples follow:
codeblock:
def test(field): if field is None: return "value is null" else: return field expression:
test(!field!) The result from above is:
input row 1 = , output = input row 2 = "", output = "value is null" input row 3 = "test value", output = "test value"
I can set value(s) in a field to null using:
Expression
None No matter what I try, any ArcGIS application won't recognize nulls using Python code. The only exception is the Python command line in ArcMap.
>>> arg1, arg2, arg3 = "Testing", None, "this string" >>> mylist = [arg1, arg2, arg3] >>> remnull = [str(arg) for arg in mylist if arg] >>> sep = " " >>> finalval = sep.join(remnull) >>> print finalval Testing this string >>> anullval = None >>> if anullval is None: ... print "yes" ... yes >>> if not anullval: ... print "yes" ... yes I've been doing a lot of coding lately. I'm wondering if a rogue line of code hasn't corrupted something. I've used the calculatefield_management in a Python script and it does the same thing. I've used cursors and they also won't pick up nulls correctly.
I can do a uninstall/re-install or repair but I'd like to spare myself a repeat if somebody knows the cause.
I'm on ArcGIS 10.0 SP5, Basic.
أكثر...
codeblock:
def test(field): if field is None: return "value is null" else: return field expression:
test(!field!) The result from above is:
input row 1 = , output = input row 2 = "", output = "value is null" input row 3 = "test value", output = "test value"
I can set value(s) in a field to null using:
Expression
None No matter what I try, any ArcGIS application won't recognize nulls using Python code. The only exception is the Python command line in ArcMap.
>>> arg1, arg2, arg3 = "Testing", None, "this string" >>> mylist = [arg1, arg2, arg3] >>> remnull = [str(arg) for arg in mylist if arg] >>> sep = " " >>> finalval = sep.join(remnull) >>> print finalval Testing this string >>> anullval = None >>> if anullval is None: ... print "yes" ... yes >>> if not anullval: ... print "yes" ... yes I've been doing a lot of coding lately. I'm wondering if a rogue line of code hasn't corrupted something. I've used the calculatefield_management in a Python script and it does the same thing. I've used cursors and they also won't pick up nulls correctly.
I can do a uninstall/re-install or repair but I'd like to spare myself a repeat if somebody knows the cause.
I'm on ArcGIS 10.0 SP5, Basic.
أكثر...