cannot access geodatabase using windows command line

2131
5
06-29-2012 12:28 AM
geogeekgeogeek
New Contributor III
While i can set the workspace and get all the feature classes of geodatabase using Arcmap python window, i can set the workspace using windows commmand line window but i can't get the feature classes, to check if i've made a connection with the geodatabase.

the script above returns in Arcmap python windows array containing feature classes , but in commande line window it returns an empty array.

>>import arcpy 
>>arcpy.env.workspace = u'C:\\Users\\hp\\Documents\\ArcGIS\\Default.gdb'
>>arcpy.ListFeatureClasses()
>>[]


i've checked global variables in windows 7:

PYTHONPATH = C:\Program Files (x86)\ArcGIS\Desktop10.0\bin;C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy;C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Scripts
the concerned part of PATH = C:\Python26\ArcGIS10.0;C:\Python26\ArcGIS10.0\Scripts;C:\Program Files (x86)\ArcGIS\ArcSDE\pgexe\bin

Available for more details

please help i'm stuck in this problem since a week

geogeek
Tags (2)
0 Kudos
5 Replies
KimOllivier
Occasional Contributor III
Setting a workspace is just a variable, it does not test if the workspace exists.
Try a test first to debug your path. I got the same null response when using XP because of course the path is different.

>>> import arcpy
>>> arcpy.env.workspace = "c:/users/kimo/documents/arcgis/default.gdb"
>>> arcpy.ListFeatureClasses()
[]
>>> arcpy.env.workspace = r"C:\Documents and Settings\kimo\My Documents\ArcGIS\Default.gdb"
>>> arcpy.ListFeatureClasses()
[u'sea1_Buffer', u'amenity2_EliminatePolygonPar']
>>> ws = r"C:\Documents and Settings\kimo\My Documents\ArcGIS\Default.gdb"
>>> if arcpy.Exists(ws):
...     arcpy.ListFeatureClasses()
... else:
...     print "Workspace not found"
...
[u'sea1_Buffer', u'amenity2_EliminatePolygonPar']

The path does not have to be unicode u"path" but you do have to be careful with path separators.
0 Kudos
geogeekgeogeek
New Contributor III
Hello Mr Kim,


i've tried to check if the workspace exists like you have mentioned , i debug the code in Arcmap python window, when i'm sure that the code works , then i try it in windows console , but it gimme always an empty array :(.
0 Kudos
KimOllivier
Occasional Contributor III
Debug it in the console as well. Use Pythonwin because it is easier to check the syntax is correct and debug. Check if it exists again there. If the path contains backslashes then they have to be handled as escape characters in a string.  Use forward slashes instead, or a raw tag r"C:\path" or two backslashes "c:\\path".

Put the script in a python file and execute that.
You must have a really simple error that is so obvious that you cannot see it.
Maybe the path is to an empty geodatabase because you are looking at different users.
Browse to it using ArcCatalog and look there to see if there is anything there.

The path on my machine to the default.gdb is

r"C:\Users\kimo\My Documents\ArcGIS\Default.gdb"
0 Kudos
RichardDaniels
Occasional Contributor III

trying changing it to

'C:/Users/kimo/Documents/ArcGIS/Default.gdb'

0 Kudos
geogeekgeogeek
New Contributor III
Thanks Mr Kim

i've applied your recommendations but without a result.

Thanks a lot
0 Kudos