<?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 Defintion query with apostrophe name in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41424#M3298</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to create an sql expression with a variable "arrondissement" but there's a problem with some attributes that contain apostrophe (quote) in their names like :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Baie d&lt;SPAN style="color: #e23d39;"&gt;'&lt;/SPAN&gt;Urfé or L&lt;SPAN style="color: #e23d39;"&gt;'&lt;/SPAN&gt;île-Bizard-Sainte-Geneviève. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've try a few things but i'm always getting an error due to the apostrophe. It's work fine with other names that doesn't have quote.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;lyr.definitionQuery = '"Arrondisse"' + "=" + "'" + arrondissement + "'"
or
lyr.definitionQuery = '"Arrondisse"' + "=" + "'\"%s\"'" %(arrondissement)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks you for your help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 21:36:21 GMT</pubDate>
    <dc:creator>Pierre-LucBoivin</dc:creator>
    <dc:date>2021-12-10T21:36:21Z</dc:date>
    <item>
      <title>Defintion query with apostrophe name</title>
      <link>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41424#M3298</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to create an sql expression with a variable "arrondissement" but there's a problem with some attributes that contain apostrophe (quote) in their names like :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Baie d&lt;SPAN style="color: #e23d39;"&gt;'&lt;/SPAN&gt;Urfé or L&lt;SPAN style="color: #e23d39;"&gt;'&lt;/SPAN&gt;île-Bizard-Sainte-Geneviève. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've try a few things but i'm always getting an error due to the apostrophe. It's work fine with other names that doesn't have quote.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;lyr.definitionQuery = '"Arrondisse"' + "=" + "'" + arrondissement + "'"
or
lyr.definitionQuery = '"Arrondisse"' + "=" + "'\"%s\"'" %(arrondissement)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks you for your help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:36:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41424#M3298</guid>
      <dc:creator>Pierre-LucBoivin</dc:creator>
      <dc:date>2021-12-10T21:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: Defintion query with apostrophe name</title>
      <link>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41425#M3299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;no sure if this is your desired output but you probably need to express it in Unicode.&amp;nbsp; You can play around with this for testing&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; x = u"Baie d'Urfé or L'île-Bizard-Sainte-Geneviève"
&amp;gt;&amp;gt;&amp;gt; x
u"Baie d'Urf\xe9 or L'\xeele-Bizard-Sainte-Genevi\xe8ve"
&amp;gt;&amp;gt;&amp;gt; print x
Baie d'Urfé or L'île-Bizard-Sainte-Geneviève
&amp;gt;&amp;gt;&amp;gt; z = '"Arrondisse"' + "=" + "'" + x + "'" 
&amp;gt;&amp;gt;&amp;gt; z
u'"Arrondisse"=\'Baie d\'Urf\xe9 or L\'\xeele-Bizard-Sainte-Genevi\xe8ve\''
&amp;gt;&amp;gt;&amp;gt; print z
"Arrondisse"='Baie d'Urfé or L'île-Bizard-Sainte-Geneviève'
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:36:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41425#M3299</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-10T21:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: Defintion query with apostrophe name</title>
      <link>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41426#M3300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for you answer Dan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found the reason why my script doesn't work,&amp;nbsp; it's because Arcgis double my apostrophe in the attribute.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So i'm parsing this string to definition query in my script. &lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;"Arrondisse"='Baie-d'Urfé'&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and when I open the attributes tables my table is empty.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When i'm doing an selection by attribute and I double the apostrophe, it's works.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;"Arrondisse" = 'Baie-d''Urfé'&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but I can't figured out how to write it and make it works in my script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if lyr.name == "Ecoles":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = '"Arrondisse"' + "=" + "'" + arrondissement + "'" 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.definitionQuery == """"Arrondisse"=u'Baie-d'Urfé'""":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.defintionQuery = """"Arrondisse"=u'Baie-d''Urfé'"""&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;&amp;nbsp; if lyr.definitionQuery == """"Arrondisse"=u'Baie-d'UrfÃ©'""":&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #303030;"&gt;Thanks &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:36:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41426#M3300</guid>
      <dc:creator>Pierre-LucBoivin</dc:creator>
      <dc:date>2021-12-10T21:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: Defintion query with apostrophe name</title>
      <link>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41427#M3301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would try one of these:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#1 -&amp;nbsp; Use different types of quote. (EG Outer double quotes, inner single quote)
print "Hello there I'm Luke"


#2 - Use Triple quotes
print '''Hello there I'm Luke'''

#3 - Use ASCI Codes
print "Hello there I" + chr(39) + "m Luke"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:36:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41427#M3301</guid>
      <dc:creator>LukeWebb</dc:creator>
      <dc:date>2021-12-10T21:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: Defintion query with apostrophe name</title>
      <link>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41428#M3302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try it like this (by the way, you have a misspelling in the word "definition" on line 4):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL class="dp-py" start="1"&gt;&lt;LI&gt;&lt;SPAN class="keyword"&gt;if lyr.definitionQuery == &lt;SPAN class="comment"&gt;""""Arrondisse"=u"Baie-d'Urfé""""&lt;/SPAN&gt;:&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = &lt;SPAN class="comment"&gt;""""Arrondisse"=u"Baie-d''Urfé""""&amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 15:57:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41428#M3302</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-06-02T15:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: Defintion query with apostrophe name</title>
      <link>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41429#M3303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;lyr.definitionQuery = &lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue; background-color: #f6f6f6;"&gt;'"Arrondisse"' + "=" + "'" + arrondissement.replace("'","''") + "'&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000; background-color: #f6f6f6;"&gt;"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000; background-color: #f6f6f6;"&gt;If any apostrophes exist in the field's value each apostrophe will be doubled (no matter how many apostrophes are stored in the actual field value).&amp;nbsp; If no apostrophe exists the field's value will be unchanged.&amp;nbsp; Then you do not need to capture the values that contain apostrophes in any separate logic.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 16:05:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41429#M3303</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-06-02T16:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Defintion query with apostrophe name</title>
      <link>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41430#M3304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's work perfectly with the replace&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks you for all you answer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 17:03:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/defintion-query-with-apostrophe-name/m-p/41430#M3304</guid>
      <dc:creator>Pierre-LucBoivin</dc:creator>
      <dc:date>2015-06-02T17:03:45Z</dc:date>
    </item>
  </channel>
</rss>

