<?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 issue in field calculator with quotes and apostrophes. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-issue-in-field-calculator-with-quotes-and/m-p/245806#M19058</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey, as you are just looking for empty strings, try this instead:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;STRONG&gt;Expression:&lt;/STRONG&gt; Reclass(str(!COM_NAME!))
&lt;STRONG&gt;Code block:&lt;/STRONG&gt;
def Reclass(COM_NAME):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (len(COM_NAME) == 0) or (COM_NAME.isspace()):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "[No Value Listed]"
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return COM_NAME &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If a string is just '', its length is zero, while if it contains only spaces the .isspace() tool will return True.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just tried this on a few things with different quotes in them (just in Python); they worked fine. If your calculator still has a problem it may be that Arc does not like the strings with the quotes in them...?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 12:14:31 GMT</pubDate>
    <dc:creator>StacyRendall1</dc:creator>
    <dc:date>2021-12-11T12:14:31Z</dc:date>
    <item>
      <title>Python issue in field calculator with quotes and apostrophes.</title>
      <link>https://community.esri.com/t5/python-questions/python-issue-in-field-calculator-with-quotes-and/m-p/245804#M19056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am stumped on this problem.&amp;nbsp; I am using the field calculator codeblock interface within model builder to automate some tasks.&amp;nbsp; As part of that, I have a simple if then statement that I use to remove any null or blank values from the select string fields.&amp;nbsp; The problem I am having is that if there are any double quotes AND apostrophes within the strings, the code will no work.&amp;nbsp; For example, the code below will work if there are apostrohes in the field strings, but not if there are double quotes.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression: Reclass(str(!COM_NAME!))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Code block:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;def Reclass(COM_NAME):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if COM_NAME == "" or COM_NAME == " ":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "[No Value Listed]"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return COM_NAME &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;On the other hand,&amp;nbsp; if I change the expression to Reclass(str('!COM_NAME!')), it will work with double quotes but not apostrophes.&amp;nbsp; VBS can get around this issue easily, but I am just curious if there is a simple work around in python as well.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2011 15:43:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-issue-in-field-calculator-with-quotes-and/m-p/245804#M19056</guid>
      <dc:creator>JamesDewar</dc:creator>
      <dc:date>2011-07-19T15:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Python issue in field calculator with quotes and apostrophes.</title>
      <link>https://community.esri.com/t5/python-questions/python-issue-in-field-calculator-with-quotes-and/m-p/245805#M19057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure if this will work, but worth a shot.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wrap three quotes around your return value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;return """COM_NAME"""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[\CODE]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2011 20:06:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-issue-in-field-calculator-with-quotes-and/m-p/245805#M19057</guid>
      <dc:creator>ChristopherFricke1</dc:creator>
      <dc:date>2011-07-19T20:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: Python issue in field calculator with quotes and apostrophes.</title>
      <link>https://community.esri.com/t5/python-questions/python-issue-in-field-calculator-with-quotes-and/m-p/245806#M19058</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey, as you are just looking for empty strings, try this instead:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;STRONG&gt;Expression:&lt;/STRONG&gt; Reclass(str(!COM_NAME!))
&lt;STRONG&gt;Code block:&lt;/STRONG&gt;
def Reclass(COM_NAME):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (len(COM_NAME) == 0) or (COM_NAME.isspace()):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "[No Value Listed]"
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return COM_NAME &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If a string is just '', its length is zero, while if it contains only spaces the .isspace() tool will return True.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just tried this on a few things with different quotes in them (just in Python); they worked fine. If your calculator still has a problem it may be that Arc does not like the strings with the quotes in them...?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:14:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-issue-in-field-calculator-with-quotes-and/m-p/245806#M19058</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T12:14:31Z</dc:date>
    </item>
  </channel>
</rss>

