<?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: Using a Value from a list in a Query Clause in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236085#M18354</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Printing the query gives me:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"OriginObjectClassName = 'BUILDINGS'"&lt;BR /&gt;"OriginObjectClassName = 'PARKS'"&lt;BR /&gt;"OriginObjectClassName = 'ROADS'"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I substitute any of those with&amp;nbsp;&lt;EM&gt;&lt;STRONG style="background-color: #ffffff;"&gt;queryClause&lt;/STRONG&gt;&lt;/EM&gt;&lt;STRONG style="background-color: #ffffff;"&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;SPAN style="background-color: #ffffff;"&gt;it works fine for that one feature.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 17 Oct 2017 17:29:10 GMT</pubDate>
    <dc:creator>MikeEdwards</dc:creator>
    <dc:date>2017-10-17T17:29:10Z</dc:date>
    <item>
      <title>Using a Value from a list in a Query Clause</title>
      <link>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236083#M18352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to export the errors from a Topology Validation. Multiple features are being validated at once and right now the output is three feature classes (poly, line, point) containing the errors from every feature class that has been validated.&lt;/P&gt;&lt;P&gt;I'm trying to change the export to be one for each feature class geometry type combination (stripping out the errors from each individual feature class and exporting them as their own.&lt;/P&gt;&lt;P&gt;What I have right now keeps ending with an Invalid Expression error (ExecuteError: ERROR 000358: Invalid expression&lt;BR /&gt;Failed to execute (SelectLayerByAttribute).).&lt;/P&gt;&lt;P&gt;Can anyone give me a hand figuring out what I'm doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;env.workspace = "C:\Temp\Test_Data.gdb"&lt;/P&gt;&lt;P&gt;table = r"&lt;SPAN&gt;C:\Temp\&lt;/SPAN&gt;Test_Data.gdb\TOPOLOGY\ArcGIS_Errors_line"&lt;BR /&gt;field = "OriginObjectClassName"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;with arcpy.da.SearchCursor(table, field) as cursor:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;myValues_List = sorted({row[0] for row in cursor})&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for FeatureClassValue in myValues_List:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;queryClause = '"' + 'OriginObjectClassName = ' + "'" + FeatureClassValue.strip('\n') + "'" + '"'&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.MakeFeatureLayer_management("T&lt;SPAN&gt;C:\Temp\&lt;/SPAN&gt;&lt;SPAN&gt;Test_Data.gdb\TOPOLOGY\ArcGIS_Errors_line&lt;/SPAN&gt;","FEATURE_SELECTION")&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.SelectLayerByAttribute_management("FEATURE_SELECTION", "NEW_SELECTION", queryClause)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.CopyFeatures_management("FEATURE_SELECTION", env.workspace + FeatureClassValue + "_Errors")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Oct 2017 15:33:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236083#M18352</guid>
      <dc:creator>MikeEdwards</dc:creator>
      <dc:date>2017-10-17T15:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Value from a list in a Query Clause</title>
      <link>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236084#M18353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried printing the query to verify the syntax? &amp;nbsp;If so, what does it look like?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Oct 2017 17:24:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236084#M18353</guid>
      <dc:creator>MitchHolley1</dc:creator>
      <dc:date>2017-10-17T17:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Value from a list in a Query Clause</title>
      <link>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236085#M18354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Printing the query gives me:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"OriginObjectClassName = 'BUILDINGS'"&lt;BR /&gt;"OriginObjectClassName = 'PARKS'"&lt;BR /&gt;"OriginObjectClassName = 'ROADS'"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I substitute any of those with&amp;nbsp;&lt;EM&gt;&lt;STRONG style="background-color: #ffffff;"&gt;queryClause&lt;/STRONG&gt;&lt;/EM&gt;&lt;STRONG style="background-color: #ffffff;"&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;SPAN style="background-color: #ffffff;"&gt;it works fine for that one feature.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Oct 2017 17:29:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236085#M18354</guid>
      <dc:creator>MikeEdwards</dc:creator>
      <dc:date>2017-10-17T17:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Value from a list in a Query Clause</title>
      <link>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236086#M18355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your query contains additional double quotes that shouldn't be there. Try this instead:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;queryClause &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"OriginObjectClassName = '{0}'"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;FeatureClassValue&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The other thing that I am wondering... is there really an enter after the featureclass name?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Oct 2017 17:32:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236086#M18355</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2017-10-17T17:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Value from a list in a Query Clause</title>
      <link>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236087#M18356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try putting an 'r' in front of all paths. &amp;nbsp; Check below&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;#what you have&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"TC:\Temp\Test_Data.gdb\TOPOLOGY\ArcGIS_Errors_line"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"FEATURE_SELECTION"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;#what I think it should be&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"C:\Temp\Test_Data.gdb\TOPOLOGY\ArcGIS_Errors_line"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"FEATURE_SELECTION"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:54:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236087#M18356</guid>
      <dc:creator>MitchHolley1</dc:creator>
      <dc:date>2021-12-11T11:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Value from a list in a Query Clause</title>
      <link>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236088#M18357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks guys, I'll give that a shot.&lt;/P&gt;&lt;P&gt;The TC:\ was a typo, I was just shortening the path names for posting on here.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Oct 2017 17:36:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236088#M18357</guid>
      <dc:creator>MikeEdwards</dc:creator>
      <dc:date>2017-10-17T17:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Value from a list in a Query Clause</title>
      <link>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236089#M18358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It may have been a typo, but the comment made by&amp;nbsp;&lt;A href="https://community.esri.com/people/mitchh300"&gt;mitchh300&lt;/A&gt;&amp;nbsp; still is valid. Your \T will convert into a TAB and create an invalid path. Please read this blog by &lt;A href="https://community.esri.com/people/Dan_Patterson"&gt;Dan_Patterson&lt;/A&gt;&amp;nbsp;:&amp;nbsp;&lt;A href="https://community.esri.com/blogs/dan_patterson/2016/08/14/filenames-and-file-paths-in-python"&gt;/blogs/dan_patterson/2016/08/14/filenames-and-file-paths-in-python&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Oct 2017 17:47:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236089#M18358</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2017-10-17T17:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Value from a list in a Query Clause</title>
      <link>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236090#M18359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That worked!&lt;/P&gt;&lt;P&gt;Thank you very much to both of you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Oct 2017 17:48:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236090#M18359</guid>
      <dc:creator>MikeEdwards</dc:creator>
      <dc:date>2017-10-17T17:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Value from a list in a Query Clause</title>
      <link>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236091#M18360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Great that worked. If it was the suggestion made by&amp;nbsp;&lt;A href="https://community.esri.com/people/mitchh300"&gt;mitchh300&lt;/A&gt;&amp;nbsp;&amp;nbsp;that helped you resolve the problem, could you mark his comment as the correct answer?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Oct 2017 17:53:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-value-from-a-list-in-a-query-clause/m-p/236091#M18360</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2017-10-17T17:53:53Z</dc:date>
    </item>
  </channel>
</rss>

