<?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: Apostrophe in query in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/apostrophe-in-query/m-p/415704#M32745</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Chris, your expression did not work on my case but Matthew's expression did after I changed the name of the field (it was not CLASS but NAME):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = """"NAME" = 'Z''berg Park'"""&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you both for your help!!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 19 Nov 2012 17:56:22 GMT</pubDate>
    <dc:creator>ionarawilson1</dc:creator>
    <dc:date>2012-11-19T17:56:22Z</dc:date>
    <item>
      <title>Apostrophe in query</title>
      <link>https://community.esri.com/t5/python-questions/apostrophe-in-query/m-p/415700#M32741</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How can I make this query work?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = '"CLASS" = \'Z'berg Park\''&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know it is not working because of the apostrophe on the name. Any ideas on what I should change? Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Nov 2012 14:46:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/apostrophe-in-query/m-p/415700#M32741</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2012-11-19T14:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Apostrophe in query</title>
      <link>https://community.esri.com/t5/python-questions/apostrophe-in-query/m-p/415701#M32742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Does this work for you?&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;query = """"CLASS" = 'Z''berg Park'"""&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Nov 2012 15:00:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/apostrophe-in-query/m-p/415701#M32742</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-11-19T15:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Apostrophe in query</title>
      <link>https://community.esri.com/t5/python-questions/apostrophe-in-query/m-p/415702#M32743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Matthew,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help. But I am still getting an error message when I run the code. Please see code snippet:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, sys, traceback

arcpy.env.workspace = "C:\\PYTHON_PRIMER\\Chapter05\\Data\\"

street_class2 = "Sacramento_Streets.shp"
street_layer2 = "Streets"
out_streets2 = "out_streets.shp"
neighborhood_class2 = "Sacramento_Neighborhoods.shp"
neighborhood_layer2 = "Neighborhoods"




try:

&amp;nbsp;&amp;nbsp;&amp;nbsp; # 1. Make a feature layer for streets

&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists(neighborhood_layer2):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(neighborhood_layer2)

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(neighborhood_class2, neighborhood_layer2)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # 2. Create a query statement to select highways

&amp;nbsp;&amp;nbsp;&amp;nbsp; query = """"CLASS" = 'Z''berg Park'"""

&amp;nbsp;&amp;nbsp;&amp;nbsp; # 3. Select by attributes using the query

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select features by attribute using query
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(neighborhood_layer2, "NEW_SELECTION", query)
&amp;nbsp;&amp;nbsp;&amp;nbsp; result2 = arcpy.GetCount_management(neighborhood_layer2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Number of selected features in the feature layer " + neighborhood_layer2 + " with a query: "+ str(result2)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # 4. Make feature layer

&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists(street_layer2):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(street_layer2)

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(street_class2, street_layer2)


&amp;nbsp;&amp;nbsp; # Create query statement
&amp;nbsp;&amp;nbsp;&amp;nbsp; query2 = '"CLASS" = \'C\''


&amp;nbsp;&amp;nbsp; #4.a Select "local" streets inside Meadowview
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(street_layer2, "NEW_SELECTION", query2)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And the error message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PYTHON ERRORS:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback Info:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\PYTHON_PRIMER\Chapter05\exercise5extra.py", line 48, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(neighborhood_layer2, "NEW_SELECTION", query)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error Info:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: ERROR 000358: Invalid expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (SelectLayerByAttribute).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Line 48 is:&amp;nbsp; arcpy.SelectLayerByAttribute_management(neighborhood_layer2, "NEW_SELECTION", query)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:50:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/apostrophe-in-query/m-p/415702#M32743</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2021-12-11T18:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: Apostrophe in query</title>
      <link>https://community.esri.com/t5/python-questions/apostrophe-in-query/m-p/415703#M32744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This format works for me:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;query = "CLASS = 'Z''berg Park'"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Nov 2012 17:27:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/apostrophe-in-query/m-p/415703#M32744</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-11-19T17:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Apostrophe in query</title>
      <link>https://community.esri.com/t5/python-questions/apostrophe-in-query/m-p/415704#M32745</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Chris, your expression did not work on my case but Matthew's expression did after I changed the name of the field (it was not CLASS but NAME):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = """"NAME" = 'Z''berg Park'"""&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you both for your help!!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Nov 2012 17:56:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/apostrophe-in-query/m-p/415704#M32745</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2012-11-19T17:56:22Z</dc:date>
    </item>
  </channel>
</rss>

