<?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: How to get variables into Python code block of arcpy.management.CalculateField in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-get-variables-into-python-code-block-of/m-p/1236961#M8081</link>
    <description>&lt;P&gt;I think it has to do with the properties of the buffer_radius field.&amp;nbsp; Maybe there's something amiss with regards to scale and precision that won't let numbers like&amp;nbsp;2043.8900146484375 and&amp;nbsp;4087.780029296875 fit inside it.&amp;nbsp; Or, if buffer_radius is a text field, maybe it's not long enough.&amp;nbsp; What can you tell us about that field?&lt;/P&gt;</description>
    <pubDate>Thu, 01 Dec 2022 20:03:17 GMT</pubDate>
    <dc:creator>RogerDunnGIS</dc:creator>
    <dc:date>2022-12-01T20:03:17Z</dc:date>
    <item>
      <title>How to get variables into Python code block of arcpy.management.CalculateField</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-get-variables-into-python-code-block-of/m-p/1236779#M8074</link>
      <description>&lt;P&gt;I have one calculation where it works great getting a variable in:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(sector_angle, 'Buffer', "getBuffer(!Area!)", "PYTHON3", 
                                f"""def getBuffer(area):
                                    if area &amp;lt; {median_area}:
                                            return 1
                                    if area &amp;gt; {median_area}:
                                            return 2""", 
                                "TEXT", "NO_ENFORCE_DOMAINS")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I have another calculation on the same feature class where it does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(sector_angle, 'Buffer_Radius', "setDistance(!Buffer!)", "PYTHON3", 
                                f"""def setDistance(buffer):
                                    if buffer == 1:
                                            return {pnt[2]}
                                    elif buffer == 2:
                                            return {pnt[3]}""", "FLOAT")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some example on how the variables look:&lt;/P&gt;&lt;P&gt;pnt[2] = 2043.8900146484375&lt;/P&gt;&lt;P&gt;pnt[3] = 4087.780029296875&lt;/P&gt;&lt;P&gt;The type of both variables is float, but the resulting 'Buffer_Radius' field contains only NaN.&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TomGeo_1-1669903249036.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/57349i6CA7D7068B45C734/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TomGeo_1-1669903249036.png" alt="TomGeo_1-1669903249036.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I tried all sorts of stuff on how to get the variables into the code block, but while it was so easy in the first function, I don't have luck with the second one. How do I get my variables into the 'Buffer_radius' field?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 14:48:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-get-variables-into-python-code-block-of/m-p/1236779#M8074</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2022-12-01T14:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to get variables into Python code block of arcpy.management.CalculateField</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-get-variables-into-python-code-block-of/m-p/1236883#M8078</link>
      <description>&lt;PRE&gt;pnt[2]&lt;/PRE&gt;&lt;P&gt;can't be a variable it is a slice of pnt, so where is pnt defined? and maybe if it is somewhere try&lt;/P&gt;&lt;P&gt;p2 = pnt[2]&lt;/P&gt;&lt;P&gt;p3 = pnt[3]&lt;/P&gt;&lt;P&gt;assuming of course that the values are slices of pnt&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 17:38:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-get-variables-into-python-code-block-of/m-p/1236883#M8078</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-12-01T17:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to get variables into Python code block of arcpy.management.CalculateField</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-get-variables-into-python-code-block-of/m-p/1236961#M8081</link>
      <description>&lt;P&gt;I think it has to do with the properties of the buffer_radius field.&amp;nbsp; Maybe there's something amiss with regards to scale and precision that won't let numbers like&amp;nbsp;2043.8900146484375 and&amp;nbsp;4087.780029296875 fit inside it.&amp;nbsp; Or, if buffer_radius is a text field, maybe it's not long enough.&amp;nbsp; What can you tell us about that field?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 20:03:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-get-variables-into-python-code-block-of/m-p/1236961#M8081</guid>
      <dc:creator>RogerDunnGIS</dc:creator>
      <dc:date>2022-12-01T20:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to get variables into Python code block of arcpy.management.CalculateField</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-get-variables-into-python-code-block-of/m-p/1237051#M8088</link>
      <description>&lt;P&gt;Throwing a few thoughts out here.&amp;nbsp; How about using a lambda function?&amp;nbsp; Also I wonder about the use of the {}.&amp;nbsp; In't that the syntax for defining a dictionary?&amp;nbsp; I think the NAN might be because the return value is a NULL dictionary.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 22:22:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-get-variables-into-python-code-block-of/m-p/1237051#M8088</guid>
      <dc:creator>DavidAnderson_1701</dc:creator>
      <dc:date>2022-12-01T22:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get variables into Python code block of arcpy.management.CalculateField</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-get-variables-into-python-code-block-of/m-p/1237081#M8090</link>
      <description>&lt;P&gt;{} is also used in python format strings.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;median_area = 5
area = 2

func = f"""
def getBuffer(area):
    if area &amp;lt; {median_area}:
        return 1
     if area &amp;gt; {median_area}:
        return 2
"""

print(func)

def getBuffer(area):
    if area &amp;lt; 5:
        return 1
     if area &amp;gt; 5:
        return 2&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 00:19:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-get-variables-into-python-code-block-of/m-p/1237081#M8090</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-12-02T00:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get variables into Python code block of arcpy.management.CalculateField</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-get-variables-into-python-code-block-of/m-p/1237150#M8092</link>
      <description>&lt;P&gt;Thanks for all the valuable thoughts and inputs. In the end, since I had all the logic anyway in Python, I ended up using an update cursor. Time wise, it is almost the same if I run those two CalculateField runs, slightly slower...&lt;/P&gt;&lt;P&gt;I tried the whole thing of course straight in ArcGIS Pro and there my code block works. However, I think &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/560410"&gt;@RogerDunnGIS&lt;/a&gt; has a fair point talking about the format of fields. The first CalculateField run is creating the buffer field, as 'TEXT'! But my second CalculateField run is using integers in the if-statement...&lt;/P&gt;&lt;P&gt;I haven't had time to try it, but 1 should not be '1', and thereby the error source is once more found about 40 cm in front of the screen. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 09:02:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-get-variables-into-python-code-block-of/m-p/1237150#M8092</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2022-12-02T09:02:36Z</dc:date>
    </item>
  </channel>
</rss>

