1

I'am trying to find a way to copy entire fields(columns) in a feature class attribute table as lists inside a master list (python).

To illustrate it, consider the table below:

enter image description here

So the list should look something like this:

talukas = [[26190, 26191, 26192, 26193, 26194, 26195, ...], 
   [Tharad, Vadgam, Vav, Amod, Ankleshwar, Bharuch, ...],
    [None, None, None, None, None, Ahmedabad Ciy, ...] ]                                                   

I was trying this,

    features = [[row.getValue(f) for f in fields] for row in arcpy.SearchCursor(fc)]

but this gives the entire row values in sub-list and not column value.

5

Close!

features = [[row.getValue (field.name) for row in arcpy.SearchCursor (fc)] for field in arcpy.ListFields (fc)]

With da:

features = [[r[0] for r in arcpy.da.SearchCursor (fc, field.name)] for field in arcpy.ListFields (fc)]

  • Thanks @Emil , that kind of works. But in "row.getValue(field.name)" , it says object has no attribute 'name'. COuld you also show me how to do it with data access module - arcpy.da. – Jio Aug 16 '15 at 20:07
  • Hmm, strange. But since it looks like you have your fields listed in variable fields already: [[row.getValue (f) for row in arcpy.SearchCursor (fc)] for f in fields] – Emil Brundage Aug 16 '15 at 20:11
  • yes they were listed. but I also tried using arcpy.ListFields. – Jio Aug 16 '15 at 20:13
2
fields = [f.name for f in arcpy.ListFields(fc)]
theTable=arcpy.da.TableToNumPyArray(fc,fields)
  • thanks felixIP for your input. however, do you know what could be the reason for , TypeError: long() argument must be a string or a number, not 'NoneType' – Jio Aug 16 '15 at 20:41
  • It won't work with Null values – FelixIP Aug 16 '15 at 20:45
  • ok. perhaps assigning some dummy value might work with argument : null_value = "NA". – Jio Aug 16 '15 at 20:50
  • It will work, this is what I'd do anyway – FelixIP Aug 16 '15 at 20:51

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.