0

I am attempting to get a list of row numbers for any rows including either of two values (-1.797693e+308 and -2147483648) in a list of columns.

I am using an Arcpy search cursor to loop through columns based on a list of headings.

Within each loop I am looking at two columns - the Index column and the column potentially containing either of the two numbers (a) - I then want the Index Column value to be returned.

At the moment the process is successful with uncomplicated numbers (ie 1 or 2) but seems to be struggling with the two numbers I am looking for - potentially as one is actually a string and the other is a minus number.

How could I adjust this so that the loop is able to pick up these numbers / strings?

Field_List = getFieldNames(Shapefile)
Field_Matchers = ['CON',"CAT"]

Search_Fields = [s for s in Field_List if any(xs in s for xs in Field_Matchers)]

for t in Search_Fields:
        FILE = Shapefile
        fields = ["INDEX_COL"]
        fields.append(t)
        cursor = arcpy.SearchCursor(FILE)
        for row in cursor:
                a = ["-1.797693e+308", "-2147483648"]
                #print row.getValue(fields[1])
                if str(row.getValue(fields[1])) in a :
                    print (row.getValue(fields[0]))

fields =["INDEX_COL"]
  • 2
    First off, rewrite your code using DA cursors. Second, comparing numeric values as strings is extremely risky, even when you make significant formatting effort (which doesn't appear to be present here). – Vince Feb 23 '17 at 14:14
  • OK have changed over to DA cursors. What would then be the best way to search for the -1.797693e+308 value? Columns in which this value are found claim to be "Double" which obviously implies it is only numbers. How can it then be that an 'e' is being stored? – Jamie2483 Feb 23 '17 at 14:24
1

As -1.797693e+308 and -2147483648 are numbers and not strings, you need to search for these as numbers.

enter image description here

This cursor looks for your two values as numbers, and if it finds them it prints the ObjectID and then the value.

>>> with arcpy.da.SearchCursor("testPoint", ['OID@', 'BigNumbers']) as cursor:
...     for row in cursor:
...         a = [-1.797693e+308, -2147483648]
...         if row[1] in a:
...             print row[0]
...             print row[1]
...             
3
-1.797693e+308
4
-2147483648.0

In response to your comment:

How can it then be that an 'e' is being stored?

There is no e being stored. This number is very very big, the e signifies exponent. The number is actually something like

-179769300000000000000000000000000000000000000000000000000000000000000000000000000... with 308 digits after the 1

See this number at WolframAlpha

  • Be careful. Absolute comparison in double precision often fails. – Vince Feb 23 '17 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.