<?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: Field Calculate syntax error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134049#M63518</link>
    <description>&lt;P&gt;What do you want to do with nulls? Leave them null? The python syntax for null is "None".&lt;/P&gt;&lt;P&gt;So you could write something like:&lt;/P&gt;&lt;P&gt;if SC is not None:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; If (SC == "GR"):&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return "GRAIN"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; elif .... and so on&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jan 2022 20:15:36 GMT</pubDate>
    <dc:creator>AdrianWelsh</dc:creator>
    <dc:date>2022-01-14T20:15:36Z</dc:date>
    <item>
      <title>Field Calculate syntax error</title>
      <link>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134014#M63510</link>
      <description>&lt;P&gt;Trying to figure out a simple field calculate but I can't i keep getting syntax error. This is a shapefile.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to update the updateField field. The updateField is a text field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;def Reclass(SC):
    if (SC == "GR"):
        return = GRAIN
    if (SC == "WR"):
        return = WRITE
    if (SC == "PL"):
        return = PLACE

updateField = Reclass(!SC!)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 19:04:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134014#M63510</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-01-14T19:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculate syntax error</title>
      <link>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134020#M63511</link>
      <description>&lt;P&gt;If you're trying to return text, do you need quotes around your text returns?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 19:15:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134020#M63511</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2022-01-14T19:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculate syntax error</title>
      <link>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134021#M63512</link>
      <description>&lt;P&gt;Hello 2Quiker,&lt;BR /&gt;&lt;BR /&gt;Does the syntax error identify a certain line of code?&lt;/P&gt;&lt;P&gt;I wonder if your return statements need to also be in quotations to be returned as text. "GRAIN" instead of GRAIN.&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 19:17:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134021#M63512</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-01-14T19:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculate syntax error</title>
      <link>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134033#M63513</link>
      <description>&lt;P&gt;I have tried it with quotes and still get the syntax error.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;def Reclass(SC):
    if (SC == "GR"):
        return "GRAIN"
    if (SC == "WR"):
        return "WRITE"
    if (SC == "PL"):
        return "PLACE"

updateField = Reclass(!SC!)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 14 Jan 2022 19:37:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134033#M63513</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-01-14T19:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculate syntax error</title>
      <link>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134035#M63514</link>
      <description>&lt;P&gt;Total rookie mistake, I forgot to check the python parser box.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 19:41:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134035#M63514</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-01-14T19:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculate syntax error</title>
      <link>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134040#M63515</link>
      <description>&lt;P&gt;Oh no! Was it in vbscript or Arcade? At least you got it figured out!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 19:50:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134040#M63515</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2022-01-14T19:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculate syntax error</title>
      <link>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134046#M63517</link>
      <description>&lt;P&gt;It was in vbscript, so I though I had it figured out but I guess not. The following only works with one if but when adding more elif I get an error that field is not nullable. How do I handle Nulls and blanks in field calculator? The SC field dose have some nulls and blanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;def Reclass(SC):
    if (SC == "GR"):
        return "GRAIN"
    elif (SC == "WR"):
        return "WRITE"
    elif (SC == "PL"):
        return "PLACE"

updateField = Reclass(!SC!)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 20:06:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134046#M63517</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-01-14T20:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculate syntax error</title>
      <link>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134049#M63518</link>
      <description>&lt;P&gt;What do you want to do with nulls? Leave them null? The python syntax for null is "None".&lt;/P&gt;&lt;P&gt;So you could write something like:&lt;/P&gt;&lt;P&gt;if SC is not None:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; If (SC == "GR"):&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return "GRAIN"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; elif .... and so on&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 20:15:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134049#M63518</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2022-01-14T20:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculate syntax error</title>
      <link>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134073#M63519</link>
      <description>&lt;P&gt;Using what you posted if SC is not None: but still have me the error "The field is not nullable". So I check the attributes filed and there are some blanks and nulls. I am trying to run this on the how feature class table not just the selected features.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;def Reclass(SC):
 if SC not in [None, "", " "]:
    if (SC == "GR"):
        return "GRAIN"
    elif (SC == "WR"):
        return "WRITE"
    elif (SC == "PL"):
        return "PLACE"

updateField = Reclass(!SC!)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 21:14:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134073#M63519</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-01-14T21:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculate syntax error</title>
      <link>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134078#M63520</link>
      <description>&lt;LI-CODE lang="python"&gt;def Reclass(SC):
    if SC not in [None, "", " "]:
        if (SC == "GR"):
            return "GRAIN"
        elif (SC == "WR"):
            return "WRITE"
        elif (SC == "PL"):
            return "PLACE"
    else:
        return "grief a null"
  &lt;/LI-CODE&gt;&lt;P&gt;you need to tell it what to do if there is one of those no-no cases&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 21:25:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1134078#M63520</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-01-14T21:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculate syntax error</title>
      <link>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1135053#M63536</link>
      <description>&lt;P&gt;Man I could not get the field calculator to work, I kept getting that I have a syntax error.&lt;/P&gt;&lt;P&gt;I ended up just using the python window with updatecursor.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy


fc = "layer"

with arcpy.da.UpdateCursor(fc,["SC","SC2"]) as cursor:
    for row in cursor:
        if row[0] not in (None, "", " "):
            if row [0] == "GR":
                row [1]= "GRAIN"
            elif row [0] == "WR":
                row [1] = "WRITE"
            elif row [0] == "PL":
                row [1] = "PLACE"
            cursor.updateRow(row)
        else:
            pass&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 17:19:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculate-syntax-error/m-p/1135053#M63536</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-01-19T17:19:54Z</dc:date>
    </item>
  </channel>
</rss>

