<?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: Problem with SelectByAttribute in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70755#M5772</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your expression try adding an extra ' apostrophe to the string.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="sql" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14211799707146482 jive_text_macro" jivemacro_uid="_14211799707146482"&gt;&lt;P&gt;expression = """MyField = 'Gwich'&lt;STRONG&gt;'&lt;/STRONG&gt;in'"""&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is instead of Gwich'in add an extra apostrophe between the "h" and "I" characters: Gwich'&lt;STRONG&gt;'&lt;/STRONG&gt;in&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Jan 2015 20:11:55 GMT</pubDate>
    <dc:creator>JamesCrandall</dc:creator>
    <dc:date>2015-01-13T20:11:55Z</dc:date>
    <item>
      <title>Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70748#M5765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I made a script that use arcpy.SelectLayerByAttribute_management.&lt;/P&gt;&lt;P&gt;The problem that some of the unique values of the field used in this selection have a special character (') ffor example : Gwi&lt;SPAN style="color: #e23d39;"&gt;ch'in&lt;/SPAN&gt; Conservation land&lt;/P&gt;&lt;P&gt;I know that the " is the problem because I removed the in from the field and the problem happened but when I removed the ' the script run perfectly&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the selection was made automatically. I locate my field first after a function put all unique values in a table. an example of my code is in the txt file attached.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I believe that I have to change something in my expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please help me to resolve this issue?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 15:16:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70748#M5765</guid>
      <dc:creator>SaidAkif</dc:creator>
      <dc:date>2015-01-13T15:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70749#M5766</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SQL cannot take a string with an apostrophe in it, since the apostrophe is the character used by SQL to quote string values.&amp;nbsp; Your Python code will need to replace the apostrophe with '''' (4 single quotes) to let the SQL interpreter use the apostrophe character literally.&amp;nbsp; The way your code is written makes the SQL parser think you are trying to quote a string and not search for an apostrophe character.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 15:25:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70749#M5766</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-01-13T15:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70750#M5767</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I encourage you to check out &lt;A href="https://docs.python.org/2/library/stdtypes.html#str.format" rel="nofollow noopener noreferrer" target="_blank"&gt;Python string formatting&lt;/A&gt;.&amp;nbsp; Not only is using built-in string formatting more Pythonic than concatenating several strings together, I would also argue it is more readable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, I would just try restructuring the expression using string formatting to see if that works:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;expression = "{} = '{}' AND {} = '{}'".format(SelectCriteriaF&lt;I&gt;,&lt;/I&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;&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; str(list_UV_CriteriaF&lt;I&gt;&lt;J&gt;),&lt;/J&gt;&lt;/I&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;&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; SplitCriteria,
&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;&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; str(listSplit&lt;K&gt;))&lt;/K&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If that doesn't work, then you might have to try string replacement to insert an escape character before the quote.&amp;nbsp; From looking at the code, I am not sure which variable is causing the problem, so I just replaced text on both.&amp;nbsp; This might work:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;expression = "{} = '{}' AND {} = '{}'".format(SelectCriteriaF&lt;I&gt;,&lt;/I&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;&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; str(list_UV_CriteriaF&lt;I&gt;&lt;J&gt;).replace("'","&lt;A href="https://community.esri.com/" rel="nofollow noopener noreferrer" target="_blank"&gt;\\'&lt;/A&gt;"),&lt;/J&gt;&lt;/I&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;&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; SplitCriteria,
&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;&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; str(listSplit&lt;K&gt;).replace("'","&lt;A href="https://community.esri.com/" rel="nofollow noopener noreferrer" target="_blank"&gt;\\'&lt;/A&gt;"))&lt;/K&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:43:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70750#M5767</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-10T22:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70751#M5768</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;Thanks for your quick ranswer&lt;/P&gt;&lt;P&gt;I tried both solution giver by Joshua. Unfortunatly, they did not work.Also I tried to replace ' by "", but the expression don't work&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any other suggestion??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 17:26:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70751#M5768</guid>
      <dc:creator>SaidAkif</dc:creator>
      <dc:date>2015-01-13T17:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70752#M5769</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you print out an example using all the variables along with the error messages, it might help narrow down the issue.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 17:49:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70752#M5769</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-01-13T17:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70753#M5770</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you remove the single apostrophe from the source data?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;If not, can you replace it with the GRAVE ACCENT or Backtick "`"?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am unsure about ISO sql standards as it relates to the character, but it does work in a da.SearchCursor as long as it is acceptable to replace the apostrophe in the data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 18:21:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70753#M5770</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2015-01-13T18:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70754#M5771</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 see in the error message that the problem is related the the value of the field espeacially "Gwich'in Conservation land" unique value. I first remove the in from the field in the original data. but the script still crash. but when I remove the ', the script worked perfectly. I am sure that the problem is '&lt;/P&gt;&lt;P&gt;How just to specify that the interpretor (python) must deal with Gwich&amp;lt;in Conservation land as one black or one unit or I don't know??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 19:49:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70754#M5771</guid>
      <dc:creator>SaidAkif</dc:creator>
      <dc:date>2015-01-13T19:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70755#M5772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your expression try adding an extra ' apostrophe to the string.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="sql" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14211799707146482 jive_text_macro" jivemacro_uid="_14211799707146482"&gt;&lt;P&gt;expression = """MyField = 'Gwich'&lt;STRONG&gt;'&lt;/STRONG&gt;in'"""&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is instead of Gwich'in add an extra apostrophe between the "h" and "I" characters: Gwich'&lt;STRONG&gt;'&lt;/STRONG&gt;in&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 20:11:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70755#M5772</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2015-01-13T20:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70756#M5773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately without specifics of what the variables are when the code errors, or even the exact error text, those of us trying to help are grasping as straws to some extent.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 21:09:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70756#M5773</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-01-13T21:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70757#M5774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just setup an example scenario that fits the OP's issue of attempting to build a query expression that must pickup string values stored with apostrophe's in them. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The sample FeatureClass just has 2 features/rows and I populated a field called "strtest" with a string value: "Gwich'in" just like the OP has.&amp;nbsp; Then I just setup a da.SearchCursor to test out how to overcome the limitations of building an expression to include the apostrophe:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;txt = """'Gwich''in'"""
fc = r'H:\Documents\ArcGIS\Default.gdb\TestLayer'
flds = ['OBJECTID','strtest']
sql = """strtest = """ + txt
print sql
with arcpy.da.SearchCursor(fc, flds, sql) as cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("{0}, {1}".format(row[0], row[1]))
sys.exit()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By simply adding an extra apostrophe in the expression, it successfully selects the feature/row.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:43:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70757#M5774</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-10T22:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70758#M5775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;IMG alt="ErrorMessage.jpg" class="jive-image image-1" height="155" src="https://community.esri.com/legacyfs/online/50891_ErrorMessage.jpg" style="width: 691px; height: 167px;" width="690" /&gt;&lt;BR /&gt;Sorry. Here is the error message&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 21:35:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70758#M5775</guid>
      <dc:creator>SaidAkif</dc:creator>
      <dc:date>2015-01-13T21:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70759#M5776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I revisited the Help for &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//00s50000002t000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Building a query expression&lt;/A&gt;, where it states:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN style="color: #4d4d4d; text-indent: 0px;"&gt;If the string contains a single quote you will first need to use another single quote as an escape character.&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In Python, the backslash is the dominant escape character, but there are some additional escape sequences.&amp;nbsp; My sample code above that used text replacement to escape the single quote used the backslash, but ArcGIS wants users to escape a single quote by using another single quote.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The updated code worked for an example I ginned up on my machine:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;expression = "{} = '{}' AND {} = '{}'".format(SelectCriteriaF&lt;I&gt;,&amp;nbsp; &lt;/I&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;&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; str(list_UV_CriteriaF&lt;I&gt;&lt;J&gt;).replace("'","''"),&amp;nbsp; &lt;/J&gt;&lt;/I&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;&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; SplitCriteria,&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;&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; str(listSplit&lt;K&gt;).replace("'","''")) &lt;/K&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:43:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70759#M5776</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-10T22:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70760#M5777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;thanks for your answer&lt;/P&gt;&lt;P&gt;Here is my variable that will contain the value = "Gwich'in Conservation area" : "'" + str(ListUVCriteriaF&lt;I&gt;&lt;J&gt;) +&amp;nbsp; "'"&lt;/J&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;When I added """ in both side of my variable (""" + "'" + str(...) + "'" + """) it did not work (all thsi line in green so python did not recognize the variable.&lt;/P&gt;&lt;P&gt;I need a way to add the """&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Jan 2015 13:17:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70760#M5777</guid>
      <dc:creator>SaidAkif</dc:creator>
      <dc:date>2015-01-14T13:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70761#M5778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your variable needs to be like this in your expression:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14212424394807205" jivemacro_uid="_14212424394807205"&gt;&lt;P&gt;Gwich''in&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you see the &lt;STRONG&gt;two (2)&lt;/STRONG&gt; apostrophe's?&amp;nbsp; That's how it must be set.&amp;nbsp; How you deal with setting a variable will be up to you because you will need to check to see an apostrophe exists and if so then double it up.&amp;nbsp; I cannot understand the code you posted.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Jan 2015 13:36:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70761#M5778</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2015-01-14T13:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SelectByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70762#M5779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;BR /&gt;Indeed, when I replace&amp;nbsp; ' by '', it works. I used the last Joshua code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help guys&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Jan 2015 15:12:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectbyattribute/m-p/70762#M5779</guid>
      <dc:creator>SaidAkif</dc:creator>
      <dc:date>2015-01-14T15:12:41Z</dc:date>
    </item>
  </channel>
</rss>

