Cursor fails to read fields correctly

by Craig T   Last Updated January 12, 2018 21:22 PM

I have a csv file that arc reads the headers incorrectly on.

The first line of my csv file is as follows: PrimaryKey, Name1, Name2, Name3, Name4, Name5, Name6, Name7

When i try to run a cursor I get a field not found error, and when I run the following code I get the included mystifying result:

>>> print [ for x in arcpy.ListFields(r'C:\PathToMyCsv')]
[u'PrimaryKey', u'Name1', u'Name2', u'Name3', u'Name4', u'GravesiteN', u'Name6', u'Name7']

"GravesiteN" appears nowhere in the file! GravesiteN is the field name for a different cursor in a different process I run frequently on my computer, but it is not in this file at all. I am mystified as to what is going on and hope you can help.

Things I've tried, in no particular order: restarting Arc, restarting my machine, converting the csv to a dbf(the incorrect field name is included in the conversion), opening the file in excel (the headers are correct), typing the headers into the file manually, using UpdateCursor instead of SearchCursor, and bashing my head on various things.

Any help would be greatly appreciated.

Related Questions

How to access adjacent rows with cursor?

Updated July 28, 2015 13:09 PM

Exporting shapefile to csv with cursor

Updated April 24, 2015 04:09 AM

Reshaping object in arcpy.da.UpdateCursor

Updated May 30, 2017 14:22 PM