<?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 field calculator syntax in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277775#M21444</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I did.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is the error I'm getting when I run it in the field calc gp tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000989&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Python syntax error: Parsing error : invalid syntax (line 1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]11590[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 31 Jan 2012 21:11:42 GMT</pubDate>
    <dc:creator>MarcGuidry</dc:creator>
    <dc:date>2012-01-31T21:11:42Z</dc:date>
    <item>
      <title>Python field calculator syntax</title>
      <link>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277769#M21438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I keep getting a syntax error, but I'm not sure where the problem is.&amp;nbsp; Any suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The point of this is to concatenate a Last name field and First name field separated by a comma if there is both a last and first name.&amp;nbsp; If one of the fields is blank, it leaves out the comma (there are no nulls).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def name (!OWNER1_LAST_NAME!, !OWNER1_FIRST_NAME!) if len(!OWNER1_FIRST_NAME!)&amp;gt;0 and len(!OWNER1_LAST_NAME!)&amp;gt;0: &amp;nbsp; return !OWNER1_LAST_NAME! &amp;amp; ', ' &amp;amp; !OWNER1_FIRST_NAME! else: &amp;nbsp; return !OWNER1_FIRST_NAME!+!OWNER1_LAST_NAME!&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;name (!OWNER1_LAST_NAME!, !OWNER1_FIRST_NAME!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Marc&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jan 2012 20:00:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277769#M21438</guid>
      <dc:creator>MarcGuidry</dc:creator>
      <dc:date>2012-01-31T20:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Python field calculator syntax</title>
      <link>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277770#M21439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Python's concatenate character is +, not &amp;amp;.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jan 2012 20:05:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277770#M21439</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2012-01-31T20:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: Python field calculator syntax</title>
      <link>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277771#M21440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I corrected that, but there is still a syntax error.&amp;nbsp; see anything else?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def name (!OWNER1_LAST_NAME!, !OWNER1_FIRST_NAME!)
if len(!OWNER1_FIRST_NAME!)&amp;gt;0 and len(!OWNER1_LAST_NAME!)&amp;gt;0:
&amp;nbsp; return !OWNER1_LAST_NAME! + ', ' + !OWNER1_FIRST_NAME!
else:
&amp;nbsp; return !OWNER1_FIRST_NAME!+!OWNER1_LAST_NAME!
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;name (!OWNER1_LAST_NAME!, !OWNER1_FIRST_NAME!)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:31:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277771#M21440</guid>
      <dc:creator>MarcGuidry</dc:creator>
      <dc:date>2021-12-11T13:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: Python field calculator syntax</title>
      <link>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277772#M21441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Looks like missing colon at end of function definition&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def name (!OWNER1_LAST_NAME!, !OWNER1_FIRST_NAME!)&lt;STRONG&gt;:&lt;/STRONG&gt; # add this
&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(!OWNER1_FIRST_NAME!)&amp;gt;0 and len(!OWNER1_LAST_NAME!)&amp;gt;0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return !OWNER1_LAST_NAME! + ', ' + !OWNER1_FIRST_NAME!
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return !OWNER1_FIRST_NAME!+!OWNER1_LAST_NAME!&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:31:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277772#M21441</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T13:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Python field calculator syntax</title>
      <link>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277773#M21442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've fixed that and there's still a syntax error.&amp;nbsp; Argh!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def name1 (!OWNER1_LAST_NAME!, !OWNER1_FIRST_NAME!):
&amp;nbsp; if len(!OWNER1_FIRST_NAME!)&amp;gt;0 and len(!OWNER1_LAST_NAME!)&amp;gt;0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return !OWNER1_LAST_NAME! + ', ' + !OWNER1_FIRST_NAME!
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return !OWNER1_FIRST_NAME!+!OWNER1_LAST_NAME!
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;name1 (!OWNER1_LAST_NAME!, !OWNER1_FIRST_NAME!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:31:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277773#M21442</guid>
      <dc:creator>MarcGuidry</dc:creator>
      <dc:date>2021-12-11T13:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python field calculator syntax</title>
      <link>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277774#M21443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Did you change the indentation as my code shows as well?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jan 2012 20:49:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277774#M21443</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-01-31T20:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: Python field calculator syntax</title>
      <link>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277775#M21444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I did.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is the error I'm getting when I run it in the field calc gp tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000989&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Python syntax error: Parsing error : invalid syntax (line 1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]11590[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jan 2012 21:11:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277775#M21444</guid>
      <dc:creator>MarcGuidry</dc:creator>
      <dc:date>2012-01-31T21:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Python field calculator syntax</title>
      <link>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277776#M21445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Oh, right. You pass in the arguments as fields:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;name1(!OWNER1_LAST_NAME!, !OWNER1_FIRST_NAME!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the code block, you reference the arguments as variables:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def name1 (lastname, firstname):
&amp;nbsp; if len(firstname)&amp;gt;0 and len(lastname)&amp;gt;0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return lastname + ', ' + firstname
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return firstname + lastname&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See the example for Using Code Blocks &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004s000000" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:31:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277776#M21445</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T13:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Python field calculator syntax</title>
      <link>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277777#M21446</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Oh sorry, you need to take those exclamation points out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def name1 (OWNER1_LAST_NAME, OWNER1_FIRST_NAME): &amp;nbsp; if len(OWNER1_FIRST_NAME)&amp;gt;0 and len(OWNER1_LAST_NAME)&amp;gt;0: &amp;nbsp;&amp;nbsp;&amp;nbsp; return OWNER1_LAST_NAME + ', ' + OWNER1_FIRST_NAME &amp;nbsp; else: &amp;nbsp;&amp;nbsp;&amp;nbsp; return OWNER1_FIRST_NAME+OWNER1_LAST_NAME&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;name1(!OWNER1_LAST_NAME!, !OWNER1_FIRST_NAME!)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry it took so long to spot that, I don't use the calculator much, prefer &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000003m000000" rel="nofollow" target="_blank"&gt;UpdateCursor&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jan 2012 21:33:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277777#M21446</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-01-31T21:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Python field calculator syntax</title>
      <link>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277778#M21447</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks folks.&amp;nbsp; I finally ended up using the UpdateCursor.&amp;nbsp; Worked like a charm.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Feb 2012 14:42:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-field-calculator-syntax/m-p/277778#M21447</guid>
      <dc:creator>MarcGuidry</dc:creator>
      <dc:date>2012-02-01T14:42:40Z</dc:date>
    </item>
  </channel>
</rss>

