What threw me of is your use of the "in" operator to compare strings. Your code would remove "contours","contour1", and "xcontour" because you are using "in" instead of "==" in your remove test
curious as to what´s bugged/why my code doesn´t work for you.
"ras_test2" in l
for l in list(ld): if l == "contour": ld.remove(l)
>>> arcpy.env.workspace=("e:/test") >>> ld = arcpy.ListDatasets("*","Raster") >>> print ld [u'myrasout.asc', u'ras_test2', u'ras_test22.asc', u'ras_test22.tif', u'ras_test2_2', u'ras_test3', u'ras_test3_3'] >>> for l in ld: ... if "myrasout" in l: # the one i´d like to filter out ... ld.remove(l) ... >>> print ld [u'ras_test2', u'ras_test22.asc', u'ras_test22.tif', u'ras_test2_2', u'ras_test3', u'ras_test3_3']
ld1 = [ds for ds in arcpy.ListDatasets("*","Raster") if "myrasout" not in ds] >>> print ld1 [u'ras_test2', u'ras_test22.asc', u'ras_test22.tif', u'ras_test2_2', u'ras_test3', u'ras_test3_3']
you could try this: ... dsets = arcpy.ListDatasets("*","Feature") rsets = [] for dataset in dsets: if dataset != "contour": rsets.append(dataset) for ds in rsets: print ds ...
... dsets = arcpy.ListDatasets("*","Feature") rsets = [] for dataset in dsets: if dataset != "contour": rsets.append(dataset) for ds in rsets: print ds ...
dsets = arcpy.ListDatasets("*","Feature") if "contour" in dsets: dsets.remove("contour")
dsets = [ds for ds in arcpy.ListDatasets("*","Feature") if ds != "contour"]
... dsets = arcpy.ListDatasets("*","Feature") for dataset in dsets: if "contour" in dataset: dsets.remove(dataset) for ds in dsets: print ds ...
dsets = [ds for ds in arcpy.ListDatasets("*","Feature") if "contour" not in ds]
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.