<?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 ArcPro Calculate Field with Python Code Block in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcpro-calculate-field-with-python-code-block/m-p/134369#M5772</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a dataset for utility work permits and we recently started tracking applicant email addresses so I am looking for help in writing a script for the Code Block field to do the bulk of the work of populating emails for the applicants that have more than one permit.&amp;nbsp; The logic behind this would essentially be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if ContactName = Joe Schmo&lt;/P&gt;&lt;P&gt;return &lt;A href="mailto:joe.schmo@gmail"&gt;joe.schmo@gmail&lt;/A&gt;.com in the email field&lt;/P&gt;&lt;P&gt;elif ContactName = Jane Doe&lt;/P&gt;&lt;P&gt;return &lt;A href="mailto:jane.doe@yahoo.com"&gt;jane.doe@yahoo.com&lt;/A&gt; in the email field&lt;/P&gt;&lt;P&gt;then if ContactName = anything else&lt;/P&gt;&lt;P&gt;return nothing&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to add more cases to cover more bases, but only spelt out those 3 for brevity.&amp;nbsp; I have searched and searched already for previous examples and have tried to write several bits to try to accomplish this but to no avail.&amp;nbsp; Here are the two bits I have tried to run and have gotten nowhere with both:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Email = Reclass(!Email!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def Reclass(Email):&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (ContactName = Joe Schmo)&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:joe.schmo@gmail.com"&gt;joe.schmo@gmail.com&lt;/A&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;elif (ContactName = Jane Doe)&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:jane.doe@yahoo.com"&gt;jane.doe@yahoo.com&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;_____________________________________________&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;fieldName = "Email" &amp;nbsp;&lt;BR /&gt;expression = "getClass(!ContactName!, Email!)" &amp;nbsp;&lt;BR /&gt;codeblock = """def getClass(ContactName, Email): &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ContactName == 'Joe Schmo': &amp;nbsp;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return "&lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:joe.schmo@gmail.com"&gt;joe.schmo@gmail.com&lt;/A&gt;&lt;SPAN&gt;" &amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;else: &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return !Email!""" &amp;nbsp;&lt;BR /&gt;arcpy.CalculateField_management(out_feature_class, fieldName, expression, "PYTHON_9.3", codeblock)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;______________________________________________&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using ArcPro, so I know the version of Python that it uses is different than ArcMap's, but that is literally all I know.&amp;nbsp; I do not know what the differences in the syntaxes are and I do not have experience with any syntax or calling functions with Python or any scripting language.&amp;nbsp; I have next to no background in scripting, so any help on how to set this up in the Code Block would be greatly appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 23 May 2018 21:08:51 GMT</pubDate>
    <dc:creator>abogedain</dc:creator>
    <dc:date>2018-05-23T21:08:51Z</dc:date>
    <item>
      <title>ArcPro Calculate Field with Python Code Block</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpro-calculate-field-with-python-code-block/m-p/134369#M5772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a dataset for utility work permits and we recently started tracking applicant email addresses so I am looking for help in writing a script for the Code Block field to do the bulk of the work of populating emails for the applicants that have more than one permit.&amp;nbsp; The logic behind this would essentially be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if ContactName = Joe Schmo&lt;/P&gt;&lt;P&gt;return &lt;A href="mailto:joe.schmo@gmail"&gt;joe.schmo@gmail&lt;/A&gt;.com in the email field&lt;/P&gt;&lt;P&gt;elif ContactName = Jane Doe&lt;/P&gt;&lt;P&gt;return &lt;A href="mailto:jane.doe@yahoo.com"&gt;jane.doe@yahoo.com&lt;/A&gt; in the email field&lt;/P&gt;&lt;P&gt;then if ContactName = anything else&lt;/P&gt;&lt;P&gt;return nothing&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to add more cases to cover more bases, but only spelt out those 3 for brevity.&amp;nbsp; I have searched and searched already for previous examples and have tried to write several bits to try to accomplish this but to no avail.&amp;nbsp; Here are the two bits I have tried to run and have gotten nowhere with both:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Email = Reclass(!Email!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def Reclass(Email):&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (ContactName = Joe Schmo)&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:joe.schmo@gmail.com"&gt;joe.schmo@gmail.com&lt;/A&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;elif (ContactName = Jane Doe)&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:jane.doe@yahoo.com"&gt;jane.doe@yahoo.com&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;_____________________________________________&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;fieldName = "Email" &amp;nbsp;&lt;BR /&gt;expression = "getClass(!ContactName!, Email!)" &amp;nbsp;&lt;BR /&gt;codeblock = """def getClass(ContactName, Email): &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ContactName == 'Joe Schmo': &amp;nbsp;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return "&lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:joe.schmo@gmail.com"&gt;joe.schmo@gmail.com&lt;/A&gt;&lt;SPAN&gt;" &amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;else: &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return !Email!""" &amp;nbsp;&lt;BR /&gt;arcpy.CalculateField_management(out_feature_class, fieldName, expression, "PYTHON_9.3", codeblock)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;______________________________________________&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using ArcPro, so I know the version of Python that it uses is different than ArcMap's, but that is literally all I know.&amp;nbsp; I do not know what the differences in the syntaxes are and I do not have experience with any syntax or calling functions with Python or any scripting language.&amp;nbsp; I have next to no background in scripting, so any help on how to set this up in the Code Block would be greatly appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2018 21:08:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpro-calculate-field-with-python-code-block/m-p/134369#M5772</guid>
      <dc:creator>abogedain</dc:creator>
      <dc:date>2018-05-23T21:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPro Calculate Field with Python Code Block</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpro-calculate-field-with-python-code-block/m-p/134370#M5773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #3d3d3d; font-family: arial,helvetica,'helvetica neue',verdana,sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; word-wrap: break-word;"&gt;expression = "getClass(!ContactName!, Email!)" &lt;/SPAN&gt;&amp;nbsp; missing ! before Email, assuming Email is a field&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2018 21:52:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpro-calculate-field-with-python-code-block/m-p/134370#M5773</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-05-23T21:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPro Calculate Field with Python Code Block</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpro-calculate-field-with-python-code-block/m-p/134371#M5774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, "Email" is a field.&amp;nbsp; Other than that missing !, should that bit of code do the operation I mean it to?&amp;nbsp; Also, if I want to add other cases to run in the same code, would I use "elif", "else", or "if" for the remaining cases before the null case?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2018 22:38:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpro-calculate-field-with-python-code-block/m-p/134371#M5774</guid>
      <dc:creator>abogedain</dc:creator>
      <dc:date>2018-05-23T22:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPro Calculate Field with Python Code Block</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpro-calculate-field-with-python-code-block/m-p/134372#M5775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# ---- d is a dictionary&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fld is emulating your field&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; my_func is a sample function to which you pass the field&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Then you 'call' the function passing the field name (ie would have ! ! around it&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;#&amp;nbsp; sample print, but you would use 'return' instead&lt;/SPAN&gt;
d &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'bob'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'bob_email'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'bee'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'bee_email'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'sue'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'sue_email'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'sie'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'sie_email'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;

fld &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'sue'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'bob'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'sie'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'no_one'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;my_func&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fld&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="string token"&gt;"""sample function"""&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; i &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; fld&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; i &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; d&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;keys&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; d&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; None
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;val&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 

my_func&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fld&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
sue_email
bob_email
sie_email
None&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;if elif else does the program flow control &amp;nbsp;&lt;A href="https://docs.python.org/3.6/tutorial/controlflow.html" rel="nofollow noopener noreferrer" target="_blank"&gt;https://docs.python.org/3.6/tutorial/controlflow.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;but if it is going to get ridiculously long, you might want to consider an alternate approach, like using a dictionary.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:31:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpro-calculate-field-with-python-code-block/m-p/134372#M5775</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T07:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPro Calculate Field with Python Code Block</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpro-calculate-field-with-python-code-block/m-p/134373#M5776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with Dan, this will get messy and impossible to manage fairly quickly.&amp;nbsp; I think a better approach overall would be to maintain a separate table of users and their e-mail addresses.&amp;nbsp; Then, you can do a join of the user e-mail address table with the permit table.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 May 2018 13:34:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpro-calculate-field-with-python-code-block/m-p/134373#M5776</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-05-24T13:34:14Z</dc:date>
    </item>
  </channel>
</rss>

