Python error: use "*" in a function parameter

09-22-2016 05:52 AM
New Contributor II


When using this function:

arcpy.da.FeatureClassToNumPyArray(featureClass, "*")

With an asterisk in the second parameter I get this error in Pyscripter:

TypeError: long() argument must be a string or a number, not 'NoneType'

While when I put the name of a field or a some fields I have no problem.

According to ESRI help, this parameter can be populated with:

A list (or tuple) of field names. For a single field, you can use a string instead of a list of strings.

Or use an asterisk (*) instead of a list of fields if you want to access all fields from the input table.

What am I doing wrong?


0 Kudos
5 Replies
MVP Frequent Contributor

What's wrong with listing out the fields?  It's a good practice to be explicit in the fields you want to work with anyway.  However, if you must use all of the fields then you can just easily build a list of them:

eflds = [ for f in arcpy.ListFields(MyFeatureclass)]
MVP Esteemed Contributor

You mention passing a field or some fields, what if you pass all fields like jamesfreddyc‌ suggests?

The error suggests that a NULL in the data (which is returned as NoneType) is failing to be coerced into a Long data type.  In order to troubleshoot anymore, the field that contains the problematic data needs to be isolated.

Does your feature class contain any NULL or empty geometries?

New Contributor II

Thanks Joshua, I found a null value in one of the fields

0 Kudos
MVP Esteemed Contributor

Look at the skip_nulls and null_value parameters in the documentation.

0 Kudos
MVP Legendary Contributor

As a suggestion, when you are using parameters, read their case requirements explicitly

in your case

FeatureClassToNumPyArray (in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {skip_nulls}, {null_value}).  

The keyword arguments (**kwargs) already has a default.  It has been my experience also, that if a kwarg has a default, don't specify it.  The default should really be an empty list/tuple and not a string, which it does.  You would have obtained all the fields if you had left out your second parameter altogether OR specified all the field names within a tuple as James showed you how to do.

0 Kudos