<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I exclude a dataset from the ListDatasets collection in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22650#M1765</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;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&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;that´s true, sloppy on my part.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Nov 2012 14:37:38 GMT</pubDate>
    <dc:creator>RaphaelR</dc:creator>
    <dc:date>2012-11-14T14:37:38Z</dc:date>
    <item>
      <title>How do I exclude a dataset from the ListDatasets collection</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22643#M1758</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would like to run a gp tool on a list of data sets in sde. I would however, like to exclude one data set called countours from the process if possible. Does anyone here know how that might be done? Any help you all can give me will be greatly appreciated. Below is an example of the code I am using.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Josh Calhoun&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;City of Chattanooga, GIS&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import time&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = (r'Database Connections\GADMIN.sde')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fgdb = (r'E:\ChattGIS.gdb')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.Delete_management(fgdb)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CreateFileGDB_management(r'E:', "ChattGIS.gdb")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for ds in arcpy.ListDatasets("*","Feature"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print ds&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outds = fgdb +"\\"+ ds[16:]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Copy_management(ds, outds)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outparcelLocator = fgdb +"\\"+ "Parcels"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outstreetLocator = fgdb +"\\"+ "Streets"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.Copy_management ('Database Connections\GADMIN.sde\GADMIN.Parcels', outparcelLocator)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.Copy_management ('Database Connections\GADMIN.sde\GADMIN.Streets', outparcelLocator)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2012 13:00:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22643#M1758</guid>
      <dc:creator>JoshCalhoun1</dc:creator>
      <dc:date>2012-11-13T13:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I exclude a dataset from the ListDatasets collection</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22644#M1759</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;you could try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
...

dsets = arcpy.ListDatasets("*","Feature")

for dataset in dsets:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if "contour" in dataset:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dsets.remove(dataset)

for ds in dsets:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print ds
...
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or a list comprehension:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dsets = [ds for ds in arcpy.ListDatasets("*","Feature") if "contour" not in ds]
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:55:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22644#M1759</guid>
      <dc:creator>RaphaelR</dc:creator>
      <dc:date>2021-12-10T20:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I exclude a dataset from the ListDatasets collection</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22645#M1760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the suggestion but I was not able to get that to work. Instead of looping through each dataset I have it hardcoded for each data set. Unfortunately, I have run out of time for more troubleshooting. There are other projects I have to get started with.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Again Thanks for your help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2012 15:30:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22645#M1760</guid>
      <dc:creator>JoshCalhoun1</dc:creator>
      <dc:date>2012-11-13T15:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I exclude a dataset from the ListDatasets collection</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22646#M1761</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Unfortunately, I believe there were bugs in Rafael's code. These should work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
dsets = arcpy.ListDatasets("*","Feature")
if "contour" in dsets:
&amp;nbsp; dsets.remove("contour")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The list comprehension version is kind of tricky to read, but it works too:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dsets = [ds for ds in arcpy.ListDatasets("*","Feature") if ds != "contour"]
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:55:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22646#M1761</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-10T20:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I exclude a dataset from the ListDatasets collection</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22647#M1762</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;you could try this:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
...

dsets = arcpy.ListDatasets("*","Feature")
rsets = []

for dataset in dsets:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if dataset != "contour":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rsets.append(dataset)

for ds in rsets:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print ds
...
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Often trying to remove stuff from a set/list confuses things/orders.&amp;nbsp; I would probably just make a new list exculding what you don't want.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:55:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22647#M1762</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-10T20:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I exclude a dataset from the ListDatasets collection</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22648#M1763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;curious as to what´s bugged/why my code doesn´t work for you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;here´s what i get when i try in arcmap python window, seems to do ok:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; arcpy.env.workspace=("e:/test")
&amp;gt;&amp;gt;&amp;gt; ld = arcpy.ListDatasets("*","Raster")
&amp;gt;&amp;gt;&amp;gt; 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']

&amp;gt;&amp;gt;&amp;gt; for l in ld:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "myrasout" in l:&amp;nbsp; # the one i´d like to filter out
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ld.remove(l)
... 
&amp;gt;&amp;gt;&amp;gt; print ld
[u'ras_test2', u'ras_test22.asc', u'ras_test22.tif', u'ras_test2_2', u'ras_test3', u'ras_test3_3']
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
ld1 = [ds for ds in arcpy.ListDatasets("*","Raster") if "myrasout" not in ds]
&amp;gt;&amp;gt;&amp;gt; print ld1
[u'ras_test2', u'ras_test22.asc', u'ras_test22.tif', u'ras_test2_2', u'ras_test3', u'ras_test3_3']&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:55:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22648#M1763</guid>
      <dc:creator>RaphaelR</dc:creator>
      <dc:date>2021-12-10T20:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I exclude a dataset from the ListDatasets collection</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22649#M1764</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;curious as to what´s bugged/why my code doesn´t work for you.&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rafael, your code has two problems I should have pointed out directly. These are both things that have tripped me up so I think they are worth sharing with the list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. You used of the "in" operator instead of "==" to compare strings. This could give you unexpected results because &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;"ras_test2" in l&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;would give a true for elements "ras_test2","ras_test22.asc", and "ras_test2_2". &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. This one has bit me before, and I missed it again in the code above. You should not modify a list while you are looping over it. Rhett probably has run into it, which is why he wisely makes a new list. (Note this is not an issue with the list comprehension because it is creating a new list, not modifying an existing one.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;An easy way to avoid the problem is to make a copy using list():&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for l in list(ld):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if l == "contour": ld.remove(l)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:55:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22649#M1764</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-10T20:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I exclude a dataset from the ListDatasets collection</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22650#M1765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;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&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;that´s true, sloppy on my part.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Nov 2012 14:37:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-exclude-a-dataset-from-the-listdatasets/m-p/22650#M1765</guid>
      <dc:creator>RaphaelR</dc:creator>
      <dc:date>2012-11-14T14:37:38Z</dc:date>
    </item>
  </channel>
</rss>

