<?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 Python list to where clause in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-list-to-where-clause/m-p/536648#M41989</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;What I am trying to do is create a definition query or where clause on a polygon grid feature layer. Each grid feature has a name and that name references a unique geodatabase in a directory. What I am doing is checking for a particular layer(s) in each geodatabase, saving that corresponding name in the feature layer if found, and outputting another feature layer with just the polygons that have a geodatabase with a corresponding feature class. Hopefully that wasn't too convoluted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My problem is, no matter what I've tried, I can't seem to pass this list on to something arcpy will take. Here's my code so far, simplified to just test if the geodatabase has features at all. The bold lines are where I would think I need to change to get this to work, crashes on the makefeaturelayer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
inputWorkspace = myWorkspace
dataList = list()
twnshpLyr = r"TFM_BKG.NEATLINE"
selectSearch = arcpy.SearchCursor(twnshpLyr)
for row in selectSearch:
&amp;nbsp;&amp;nbsp;&amp;nbsp; township = row.getValue("TILE_NAME")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = inputWorkspace+os.sep+township+".mdb"
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcList = arcpy.ListFeatureClasses()
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataList.append(str(township))
&amp;nbsp;&amp;nbsp;&amp;nbsp; else: continue
arcpy.MakeFeatureLayer_management(twnshpLyr, "townshipData", "TILE_NAME in (",str(dataList)+")")
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the error I get from the python window:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: Failed to execute. Parameters are not valid. ERROR 000732: Workspace or Feature Dataset: Dataset (...all the feature values in the list...) does not exist or is not supported Failed to execute (MakeFeatureLayer).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 26 Oct 2011 12:51:53 GMT</pubDate>
    <dc:creator>MathewCoyle</dc:creator>
    <dc:date>2011-10-26T12:51:53Z</dc:date>
    <item>
      <title>Python list to where clause</title>
      <link>https://community.esri.com/t5/python-questions/python-list-to-where-clause/m-p/536648#M41989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;What I am trying to do is create a definition query or where clause on a polygon grid feature layer. Each grid feature has a name and that name references a unique geodatabase in a directory. What I am doing is checking for a particular layer(s) in each geodatabase, saving that corresponding name in the feature layer if found, and outputting another feature layer with just the polygons that have a geodatabase with a corresponding feature class. Hopefully that wasn't too convoluted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My problem is, no matter what I've tried, I can't seem to pass this list on to something arcpy will take. Here's my code so far, simplified to just test if the geodatabase has features at all. The bold lines are where I would think I need to change to get this to work, crashes on the makefeaturelayer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
inputWorkspace = myWorkspace
dataList = list()
twnshpLyr = r"TFM_BKG.NEATLINE"
selectSearch = arcpy.SearchCursor(twnshpLyr)
for row in selectSearch:
&amp;nbsp;&amp;nbsp;&amp;nbsp; township = row.getValue("TILE_NAME")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = inputWorkspace+os.sep+township+".mdb"
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcList = arcpy.ListFeatureClasses()
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataList.append(str(township))
&amp;nbsp;&amp;nbsp;&amp;nbsp; else: continue
arcpy.MakeFeatureLayer_management(twnshpLyr, "townshipData", "TILE_NAME in (",str(dataList)+")")
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the error I get from the python window:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: Failed to execute. Parameters are not valid. ERROR 000732: Workspace or Feature Dataset: Dataset (...all the feature values in the list...) does not exist or is not supported Failed to execute (MakeFeatureLayer).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Oct 2011 12:51:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-list-to-where-clause/m-p/536648#M41989</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2011-10-26T12:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Python list to where clause</title>
      <link>https://community.esri.com/t5/python-questions/python-list-to-where-clause/m-p/536649#M41990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try using join:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
where = "TILE_NAME in (" + ','.join(dataList) + ")"
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;also try using idle to validate code snippets.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:18:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-list-to-where-clause/m-p/536649#M41990</guid>
      <dc:creator>KyleShannon</dc:creator>
      <dc:date>2021-12-11T23:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python list to where clause</title>
      <link>https://community.esri.com/t5/python-questions/python-list-to-where-clause/m-p/536650#M41991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;What I am trying to do is create a definition query or where clause on a polygon grid feature layer. Each grid feature has a name and that name references a unique geodatabase in a directory. What I am doing is checking for a particular layer(s) in each geodatabase, saving that corresponding name in the feature layer if found, and outputting another feature layer with just the polygons that have a geodatabase with a corresponding feature class. Hopefully that wasn't too convoluted.&lt;BR /&gt;&lt;BR /&gt;My problem is, no matter what I've tried, I can't seem to pass this list on to something arcpy will take. Here's my code so far, simplified to just test if the geodatabase has features at all. The bold lines are where I would think I need to change to get this to work, crashes on the makefeaturelayer.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
inputWorkspace = myWorkspace
dataList = list()
twnshpLyr = r"TFM_BKG.NEATLINE"
selectSearch = arcpy.SearchCursor(twnshpLyr)
for row in selectSearch:
&amp;nbsp;&amp;nbsp;&amp;nbsp; township = row.getValue("TILE_NAME")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = inputWorkspace+os.sep+township+".mdb"
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcList = arcpy.ListFeatureClasses()
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;dataList.append(str(township))&lt;/STRONG&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; else: continue
&lt;STRONG&gt;arcpy.MakeFeatureLayer_management(twnshpLyr, "townshipData", "TILE_NAME in (",str(dataList)+")")&lt;/STRONG&gt;
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Here is the error I get from the python window:&lt;BR /&gt;Runtime error &amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: Failed to execute. Parameters are not valid. ERROR 000732: Workspace or Feature Dataset: Dataset (...all the feature values in the list...) does not exist or is not supported Failed to execute (MakeFeatureLayer).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Based on your script, you tried to creat an out_layer in inputWorkspace+os.sep+township+".mdb which is invalid workspace for lyr file.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:18:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-list-to-where-clause/m-p/536650#M41991</guid>
      <dc:creator>HemingZhu</dc:creator>
      <dc:date>2021-12-11T23:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Python list to where clause</title>
      <link>https://community.esri.com/t5/python-questions/python-list-to-where-clause/m-p/536651#M41992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for all the suggestions, the where clause got me rolling in the right direction, slight modification and worked perfectly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;where = "TILE_NAME in ('" + '\',\''.join(dataList) + "')"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The workspace wasn't really an issue since I was working in memory, but a good habit to get in to nonetheless. Here's the working script now.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, os
sde = r"Database Connections\wisprod.sde"
inputWorkspace = r"\\winms-gissvr\data\new_avi_pgdb\data"
dataList = list()
twnshpLyr = r"TFM_BKG.NEATLINE"
selectSearch = arcpy.SearchCursor(twnshpLyr)
for row in selectSearch:
&amp;nbsp;&amp;nbsp;&amp;nbsp; township = row.getValue("TILE_NAME")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = inputWorkspace+os.sep+township+".mdb"
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcList = arcpy.ListFeatureClasses()
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataList.append(str(township))
&amp;nbsp;&amp;nbsp;&amp;nbsp; else: pass
arcpy.env.workspace = inputWorkspace
where = "TILE_NAME in ('" + '\',\''.join(dataList) + "')"
arcpy.MakeFeatureLayer_management(sde+os.sep+twnshpLyr, "townshipData", where)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:18:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-list-to-where-clause/m-p/536651#M41992</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T23:18:08Z</dc:date>
    </item>
  </channel>
</rss>

