Row 'isNull()' problem

604
4
Jump to solution
08-07-2013 09:31 AM
KevinYanuk
Occasional Contributor
Hello,

I am attempting to loop over a centerline shapefile and pull out specific values per field value to set as a new row value in another shapefile.

However, the code fails when the returned value is null, even when using the isNull() method as so:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001q000000

if not self.centerline.isNull(suffix):     self.newStreet.S_suffix = self.centerline.getValue(suffix)


Has anyone run into this problem with this method before?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JimCousins
MVP Regular Contributor
I have not run into this specifically, but what about putting in some error handling to allow your code to continue on past these rows?
Implement the Try-Except block statement.
Regards,
Jim

View solution in original post

0 Kudos
4 Replies
JimCousins
MVP Regular Contributor
I have not run into this specifically, but what about putting in some error handling to allow your code to continue on past these rows?
Implement the Try-Except block statement.
Regards,
Jim
0 Kudos
KevinYanuk
Occasional Contributor
I have not run into this specifically, but what about putting in some error handling to allow your code to continue on past these rows?
Implement the Try-Except block statement.
Regards,
Jim


Thanks for the reply - that is what I had to do:

                try:
                    if not self.centerline.isNull(name):
                        self.newStreet.S_name = self.centerline.getValue(name)
                except:
                    pass
                
                try:
                    if not self.centerline.isNull(prefix):
                        self.newStreet.S_prefix = self.centerline.getValue(prefix)
                except:
                    pass

                try:
                    if not self.centerline.isNull(suffix):
                        self.newStreet.S_suffix = self.centerline.getValue(suffix)
                except:
                    pass

                try:
                    if not self.centerline.isNull(type):
                        self.newStreet.S_type = self.centerline.getValue(type)
                except:
                    pass



Although, not the prettiest, I suppose it works.
0 Kudos
JamesCrandall
MVP Frequent Contributor
da.SearchCursor has some options too:


fields = ['fld1', 'fld2', 'fld3']
for field in fields:
   where = field + " IS NOT NULL"
   try:
       with arcpy.da.SearchCursor(fc, fields, where) as cursor:
          for row in cursor:
              value = row[0]
              print field + ": " + str(value) #or use "value" to do something
   except Error:
       pass

del row, cursor



note: I first tested for "IS NULL" values and simply printed them out and it correctly listed/printed the fields and the null value.  So then I just altered it to "IS NOT NULL" to get the opposite result, printing all values for each field that is not null.  I did not fully research this for better option, do additional testing or determine if this is actually incorrect --- so I am very open to critique of the above!
0 Kudos
RhettZufelt
MVP Frequent Contributor
Does this work for you?

if self.centerline.getValue(suffix) is not None:
    self.newStreet.S_suffix = self.centerline.getValue(suffix)


R_
0 Kudos