Same python code works in Arcgis python window, but fails in pyScripter.

2337
6
Jump to solution
11-11-2014 10:36 AM
ChroAhmed
New Contributor II

Same python code works in Arcgis python window, but fails in pyScripter.

This code works in the arcgis python window but in PyScripter,it shows a warring message of:

(Exceptions. IO Error: "CandidateStations_Centroid" does not exist)!

 

import arcpy

path=("C:/Users/fazeel/Desktop/ExampleCase/LeicesterCity_Leeds")

arcpy.env.workspace=path

fields=arcpy.ListFields("CandidateStations_Centroid")

for fld in fields:

    print fld.name

 

I wonder to know the reason of this warring message, any suggestion please?

 

Many thanks

0 Kudos
1 Solution

Accepted Solutions
TimothyHales
Esri Notable Contributor

It seems the reason this is working is because you have a layer named "CandidateStations_Centroid" in your ArcMap session, so it is recognized in the ListFields.

Your path is referencing a folder and not a GeoDatabase, so you would need to make sure you are pointing to the actual feature class which I am assuming is a shapefile (CandidateStations_Centroid.shp).

View solution in original post

6 Replies
DanPatterson_Retired
MVP Emeritus

try this

path = "C:/Users/fazeel/Desktop/ExampleCase/LeicesterCity_Leeds"  # non-tuple version

0 Kudos
ChroAhmed
New Contributor II

Dear Dan

Thank you very much for your response. I tried it, but again it showed the same warning message!

Best regards,

0 Kudos
JasonScheirer
Occasional Contributor III

Putting a single value in (parens) doesn't turn it into a tuple.

>>> path=("C:/Users/fazeel/Desktop/ExampleCase/LeicesterCity_Leeds")

>>> type(path)

<class 'str'>

You'd need to add a comma to get that:

>>> path=("C:/Users/fazeel/Desktop/ExampleCase/LeicesterCity_Leeds",)

>>> type(path)

<class 'tuple'>

DanPatterson_Retired
MVP Emeritus

always missing the comma...which is why I hate tuples

TimothyHales
Esri Notable Contributor

It seems the reason this is working is because you have a layer named "CandidateStations_Centroid" in your ArcMap session, so it is recognized in the ListFields.

Your path is referencing a folder and not a GeoDatabase, so you would need to make sure you are pointing to the actual feature class which I am assuming is a shapefile (CandidateStations_Centroid.shp).

ChroAhmed
New Contributor II

Dear Dan

Thank you very much you are true,once I provided the extension "gdb" it worked.

Many thanks once again

0 Kudos