<?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: Python Triple Quotes Escape Stroke in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-triple-quotes-escape-stroke/m-p/363405#M28743</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Geoff:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try breaking your query string up and using a combination of ' and ".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g. &lt;/P&gt;&lt;P&gt;queryString = r'"FID" in (%s) and "Jurisdicti" like ' + '\'\% Township\''&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 01 Oct 2014 21:06:15 GMT</pubDate>
    <dc:creator>SusanJones</dc:creator>
    <dc:date>2014-10-01T21:06:15Z</dc:date>
    <item>
      <title>Python Triple Quotes Escape Stroke</title>
      <link>https://community.esri.com/t5/python-questions/python-triple-quotes-escape-stroke/m-p/363404#M28742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using Python to run a script, but I've run into a small problem.&amp;nbsp; I'm using triple quotes to form a definition query, but inside the query is a wildcard %, so the interpreter is expecting a variable to format the string.&amp;nbsp; Is there a stroke key that can be used?&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_14121951288711111" jivemacro_uid="_14121951288711111" modifiedtitle="true"&gt;
&lt;P&gt;mapLyr2.definitionQuery = """"FID" IN (%s) AND "Jurisdicti" NOT LIKE '% Township'""" %dqStr&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Oct 2014 20:27:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-triple-quotes-escape-stroke/m-p/363404#M28742</guid>
      <dc:creator>GeoffOlson</dc:creator>
      <dc:date>2014-10-01T20:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Python Triple Quotes Escape Stroke</title>
      <link>https://community.esri.com/t5/python-questions/python-triple-quotes-escape-stroke/m-p/363405#M28743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Geoff:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try breaking your query string up and using a combination of ' and ".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g. &lt;/P&gt;&lt;P&gt;queryString = r'"FID" in (%s) and "Jurisdicti" like ' + '\'\% Township\''&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Oct 2014 21:06:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-triple-quotes-escape-stroke/m-p/363405#M28743</guid>
      <dc:creator>SusanJones</dc:creator>
      <dc:date>2014-10-01T21:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Python Triple Quotes Escape Stroke</title>
      <link>https://community.esri.com/t5/python-questions/python-triple-quotes-escape-stroke/m-p/363406#M28744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use &lt;CODE&gt;%%&lt;/CODE&gt;.&lt;/P&gt;&lt;PRE&gt;&amp;gt;&amp;gt;&amp;gt; """x like 'hello%' and y = %s"""
"x like 'hello%' and y = %s"
&amp;gt;&amp;gt;&amp;gt; """x like 'hello%' and y = %s"""%"what"
Traceback (most recent call last):
&amp;nbsp; File "", line 1, in ValueError: unsupported format character ''' (0x27) at index 14
&amp;gt;&amp;gt;&amp;gt; """x like 'hello%%' and y = %s"""%"what"
"x like 'hello%' and y = what"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Oct 2014 21:37:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-triple-quotes-escape-stroke/m-p/363406#M28744</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2014-10-01T21:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Python Triple Quotes Escape Stroke</title>
      <link>https://community.esri.com/t5/python-questions/python-triple-quotes-escape-stroke/m-p/363407#M28745</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've become more of a fan of the Python 2.x/3.x string formatting:&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_14122165439532904" jivemacro_uid="_14122165439532904"&gt;
&lt;P&gt;mapLyr2.definitionQuery = """"FID" IN ({}) AND "Jurisdicti" NOT LIKE '% Township'""".format(dqStr)&lt;/P&gt;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I like to break things up into multiple lines with () to make it easier to read and debug. Note that if you place parentheses around the expression, it will get glommed together for you into a single string for .format() to process - look ma, no line continuation characters! So elegant.&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_14122165528987229" jivemacro_uid="_14122165528987229"&gt;
&lt;P&gt;mapLyr2.definitionQuery = (&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """"FID" IN ({}) AND """&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """"Jurisdicti" NOT LIKE '% Township'""").format(dqStr)&lt;/P&gt;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm with Susan -- I also find triple quotes kind of clunky - but this is of course totally personal preference!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14122165656386528 jive_text_macro" jivemacro_uid="_14122165656386528"&gt;
&lt;P&gt;mapLyr2.definitionQuery = (&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '"FID" IN ({}) AND '&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '"Jurisdicti" NOT LIKE \'% Township\'').format(dqStr)&lt;/P&gt;


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 02:23:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-triple-quotes-escape-stroke/m-p/363407#M28745</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-10-02T02:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Python Triple Quotes Escape Stroke</title>
      <link>https://community.esri.com/t5/python-questions/python-triple-quotes-escape-stroke/m-p/363408#M28746</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all for the replies.&amp;nbsp; I will keep this in mind.&amp;nbsp; Triple quotes was my immediate solution when I realized I had both single and double quotes for the query.&amp;nbsp; My temporary solution for this was to create a string variable that was the entire wildcard part '% Township' and that worked, but I don't want to keep creating variables just for the purpose of a workaround.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 17:23:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-triple-quotes-escape-stroke/m-p/363408#M28746</guid>
      <dc:creator>GeoffOlson</dc:creator>
      <dc:date>2014-10-02T17:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Python Triple Quotes Escape Stroke</title>
      <link>https://community.esri.com/t5/python-questions/python-triple-quotes-escape-stroke/m-p/363409#M28747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another option is to use the ascii code for the character you're having trouble with. chr(37) would give you %; you just need to place it in the query string. You can deal with combinations of double and single quotes using the same approach, but it can get confusing in long queries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;mapLyr2.definitionQuery = '&lt;SPAN class="comment"&gt;FID IN ('+chr(37)+'s) AND '+chr(34)+'Jurisdicti'+chr(34)+'&lt;/SPAN&gt;&lt;SPAN class="comment"&gt; NOT LIKE ' + chr(37)+chr(39)+' Township'+chr(39)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="comment"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="comment"&gt;o&lt;/SPAN&gt;&lt;SPAN class="comment"&gt;r&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="comment"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="comment"&gt;mapLyr2.definitionQuery = '&lt;SPAN class="comment"&gt;FID IN ('+chr(37)+'s) AND '+chr(34)+'Jurisdicti'+chr(34)+'&lt;/SPAN&gt;&lt;SPAN class="comment"&gt; NOT LIKE ' + chr(37)+"'" Township"'"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 17:44:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-triple-quotes-escape-stroke/m-p/363409#M28747</guid>
      <dc:creator>JuanOrozco</dc:creator>
      <dc:date>2014-10-02T17:44:09Z</dc:date>
    </item>
  </channel>
</rss>

