AnsweredAssumed Answered

Python ArcGIS 10.1 Field Calculator If...Then Issue with None

Question asked by caroytct on Jul 3, 2012
Latest reply on Jul 3, 2012 by JScheirer-esristaff
Hi all,

I created a simple 'Code Block' python script for the Field Calculator in ArcGIS 10. It was working fine then. Since I installed ArcGIS 10.1, something strange is happening when I run it. The purpose is to concatenate 3 different text fields into a new field as Provincial Code (2 numbers) + Trail Code (4 numbers) + Section Code (1 letter). Provincial Code and Trail codes don't have Null values but the Section code has Null value in it. So when a section code exist, the Project Code will look like 01-0001A but with look like 01-0001 if no section code exists. Here is the 'Code Block' I'm using:

Expression = classify(!ID_Province!, !ID_Trail!, str(!ProjSection!))  def classify(prov, trail, section):   if section == "":     return prov + "-" + trail   else:     return prov + "-" + trail + section


So when the Section code is Null or empty, I want to concatenate provincial and trail only (don't want any space or anything else after). Then, if a section code exist, I want to concatenate all of them together. As I said, it was working fine in ArcGIS 10. With ArcGIS 10.1, the code seems to only calculate the 'else' statement. If a section code exist, the code returns as expected something like 01-0001A. However, if section code is Null, instead of having something like 01-0001 I have 01-0001None. I don't understand why None appears now at the end.

Thanks for the help

Outcomes