POST
|
It does seem to be an issue with not looping over the cursor because when I do loop over the cursor the it returns nothing, like I am expecting. with arcpy.da.SearchCursor(inFeature, (inField, inField1, inField2), where_clause2) as cursor: for row in cursor: count+=1 print("ANTHOER NULL VALUE") print(count) 0 >>> when I do not loop over the cursor: count = 0 with arcpy.da.SearchCursor(inFeature, (inField, inField1, inField2), where_clause2) as cursor: count+=1 # indentation is 2x Tab print("ANTHOER NULL VALUE") print(count) ANTHOER NULL VALUE 1 >>> >>> count = 0 with arcpy.da.SearchCursor(inFeature, (inField, inField1, inField2), where_clause2) as cursor: count+=1 ## indentation is 1x Tab print("ANOTHER NULL VALUE") print(count) ANOTHER NULL VALUE 1 >>> I was under the impression that you didn't have to loop over a cursor for it to work but maybe I was misinformed... Do you always loop over a cursor?
... View more
06-07-2019
04:17 PM
|
0
|
1
|
2605
|
POST
|
By 'Basically you are asking 'if one or more of these 3 fields is null' do you mean that I am testing if the field exists or not (that would not be what I am attempting to do) or if any value/row in any of the fields are NULL (what I am trying to do)?
... View more
06-07-2019
03:46 PM
|
0
|
2
|
2605
|
POST
|
I am trying to write a search cursor that looks through the fields in a Feature Class and if there is a NULL value in any of the fields prints the statement "NULL values present". I am having trouble getting my where_clause to work. Here is what I have: import arcpy inFeature = 'SCRIPT_PARAMETERS_TEST' inField = 'Prov' inField1 = 'Rd_Symbol' inField2 = 'Name_Type' nul = 'NULL' where_clause = inField + " IS " + nul + " or " + inField1 + " IS " + nul + " or " + inField2 + " IS " + nul with arcpy.da.SearchCursor(inFeature, (inField, inField1, inField2), where_clause) as cursor: print("NULL values present") The code runs however, there are two problems. First it prints NULL values present always, even when I change the fields to fields that are fully populated. Second I feel like there is probably a cleaner way to write the where clause... I have looked into things like: where_clause = 'field_name' is None where_clause = 'field_name' is 'NULL' where_clause = 'field_name' IS Null' but have not had success either getting a syntax error message. Or for 'field_name' is None there was no error message but when I checked the statement this is what I get: >>>> print(where_clause) FALSE If you have any suggestions or if there is a resource anyone recommends to help better understand writing SQL statements with python/arcpy that would be much appreciated.
... View more
06-06-2019
10:29 AM
|
0
|
10
|
3641
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|