Select to view content in your preferred language

.ListDatasets() doesn't seem to work in 10, did in 9.3

1098
4
09-14-2010 06:17 AM
PhilSullivan
Deactivated User
My code hangs on 'fds = arcpy.ListDatasets()' . Has anyone else experienced trouble in 10 with 'ListDatasets'? The code works fine in 9.3 using Arcgisscripting.

try:
    print " LINE 86"
    lyrs = [] #empty list
    text_file = open("\\\\clu-harrison\\DataConversion\\GIS\\GISModifiedTables.txt","r")
    for line in text_file:lyrs.append(line.strip()) #create a list of layers
    listCount = len(lyrs)
    text_file.close()
    # Loop through feature datasets in geodatabase
    print " LINE 94"
    fds = arcpy.ListDatasets()
    print fds
    print " LINE AFTER FDS = arcpy.LISTDATASETS()"
    fds.Reset()
    print "LINE AFTER FDS.RESET"
    fd = fds.Next()
    print " LINE 98"
    while fd:
        print " LINE 99"
        arcpy.Workspace = dbConnection + "\\" + fd

Thanks.
0 Kudos
4 Replies
JoelCalhoun
Deactivated User
One thing I noticed is that it appears you have an extra space in the path to your text file (.t xt)

That being said I believe they did make a change.  Instead of using a "while" loop you would now use a "for" loop.  This is the example from the help:

import arcpy

arcpy.env.workspace = "C:/Data"
# Print to the Interactive window all the feature datasets in the workspace
#   that start with the letter C. 
#
datasetList = arcpy.ListDatasets("C*", "Feature")

for dataset in datasetList:
    print dataset



The link to the help is: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000001m000000.htm


I hope this helps,


Joel
0 Kudos
StephanieSnider
Frequent Contributor
I need to list only feature datasets in a worksapce.  However, when I use ListDatasets, it also lists two raster datasets in the same workspace (last two in the list).  When I list using type 'feature', I get nothing.  How can I make this function list only feature datasets?

>>> arcpy.ListDatasets()
[u'NDEP.BLM', u'NDEP.Parcels', u'NDEP.Surrounding_States', u'NDEP.Washoe_County', u'NDEP.Geology', u'NDEP.DEPTH_TO_GROUNDWATER', u'NDEP.LAND_USE_COVER_USDA_2007']
>>> arcpy.ListDatasets('feature')
[]

Stephanie
0 Kudos
DanPatterson_Retired
MVP Emeritus
perhaps it is case-sensitive as is everything Pythonic
arcpy.ListDatasets('feature')
might be
arcpy.ListDatasets('Feature')
0 Kudos
StephanieSnider
Frequent Contributor
It's not case sensitive.

>>> ds = arcpy.ListDatasets('feature')
>>> ds
[]
>>> ds = arcpy.ListDatasets('Feature')
>>> ds
[]

Also it would help if feature datasets for different account owners did not show up under all account owners.  I'm using Oracle 11G.  For example, account NDEP has 5 feature datasets for which it is the data owner.  But these feature datasets are also listed under account BAPC which does not own the data.  This is a problem not just with python scripting, but with how ArcCatalog lists feature datasets.  If I add a feature dataset in one account, all accounts will see it (but not be able to access the feature classes within it).  It's just annoying.  And for python scripts...it is more than annoying because the listdatasets function lists datasets that are not owned by the owner.
0 Kudos