SearchCursor object() takes no parameters

972
5
12-06-2018 07:52 AM
Che-YiHung
New Contributor

Hi I'm just learning the function of SearchCursor

this is my code here

import arcpy

points = r'D:\GIS\turto\pop.shp'

with arcpy.da.SearchCursor(points,['iso_a2', 'adm0_a3']) as citycursor:
    for x in citycursor:
        print(x[0]);


and the error just show:
D:\Users\Jay\PycharmProjects\learn\venv\Scripts\python.exe D:/Users/Jay/PycharmProjects/learn/search.py
Traceback (most recent call last):
 File "D:/Users/Jay/PycharmProjects/learn/search.py", line 10, in <module>
 with arcpy.da.SearchCursor(points,['iso_a2', 'adm0_a3']) as citycursor:
TypeError: object() takes no parameters

Process finished with exit code 1

I followed the tutorial of this one

6 - Search Cursors - Arcgis Scrpting with Python - YouTube 

and I checked the syntax and other examples, all didnt help

the sitauation

I wonder what I do wrong

Please help me, thank you

Tags (2)
0 Kudos
5 Replies
MitchHolley1
MVP Regular Contributor

Please remove the ; at the end of the print statement.  I tested a search cursor on your dataset without any errors. What python version are you using?  Can you import arcpy from the interactive python IDE environment without errors?

0 Kudos
DanPatterson_Retired
MVP Emeritus

semi-colon is ok in python 3 at least

a = [1,2,3,4]

for i in a:
    print(i);
1
2
3
4
Che-YiHung
New Contributor

Hi, I can use other arcpy funtions such as search by location, so it means the arcpy in pycharm is imported correctly, right?

I'm using the python 2.7 which came with ArcGIS 10.5

I was wondering what was missing

0 Kudos
DanPatterson_Retired
MVP Emeritus

can the shapefile be viewed in ArcMap and can you confirm that the fields are indeed there

0 Kudos
Che-YiHung
New Contributor

yes, I just downloaded from the Nature Earth website for the tutorial. And as Mitch tested, the data is fine.

0 Kudos