<?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: Beginner Python Code Questions in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/beginner-python-code-questions/m-p/1190835#M57068</link>
    <description>&lt;P&gt;Thank you so much! This worked perfectly and cut down a whole block of code lol!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jul 2022 15:02:24 GMT</pubDate>
    <dc:creator>CarolynGao15</dc:creator>
    <dc:date>2022-07-08T15:02:24Z</dc:date>
    <item>
      <title>Beginner Python Code Questions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/beginner-python-code-questions/m-p/1190644#M57047</link>
      <description>&lt;P&gt;Hello!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've just started learning Python and am having a lot of trouble figuring out how to write this code/what I'm doing wrong.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a if/elif and I want to calculate the same field for each feature class. For the last feature class (PLANNING_WAY), I want to add 2 fields together (QSTRM and LLD). The problem I keep encountering is, the field LLD has null values, and once my script hits that row, it stops and says "process finished with exit code 1".&lt;/P&gt;&lt;P&gt;Therefore, I've tried rewriting my code so that if the LLD value is None, it will just populate with the QSTRM field. Now, it doesn't populate the field for PLANNING_WAY at all.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;import &lt;/SPAN&gt;arcpy&lt;BR /&gt;&lt;BR /&gt;arcpy.env.workspace = &lt;SPAN&gt;input&lt;/SPAN&gt;(&lt;SPAN&gt;"Workspace GDB: "&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# List feature classes and fields for gdb and create variables&lt;BR /&gt;&lt;/SPAN&gt;fcList = arcpy.ListFeatureClasses(&lt;SPAN&gt;input&lt;/SPAN&gt;(&lt;SPAN&gt;"List of vector dataset names to process (* for all): "&lt;/SPAN&gt;))&lt;BR /&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"Processing {}"&lt;/SPAN&gt;.format(fcList))&lt;BR /&gt;fieldnm = &lt;SPAN&gt;"EXCL_NM"&lt;BR /&gt;&lt;/SPAN&gt;exp_type = &lt;SPAN&gt;"PYTHON3"&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;# Update EXCL_NM field based on fc name using Field Calculator to concatenate field(s)&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"Populating EXCL_NM field"&lt;/SPAN&gt;)&lt;BR /&gt;&lt;SPAN&gt;for &lt;/SPAN&gt;fc &lt;SPAN&gt;in &lt;/SPAN&gt;fcList:&lt;BR /&gt;    &lt;SPAN&gt;if &lt;/SPAN&gt;fc == &lt;SPAN&gt;"TEST_land"&lt;/SPAN&gt;:&lt;BR /&gt;        arcpy.CalculateField_management(fc&lt;SPAN&gt;, &lt;/SPAN&gt;fieldnm&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'!P_LABEL!'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;exp_type)&lt;BR /&gt;    &lt;SPAN&gt;elif &lt;/SPAN&gt;fc == &lt;SPAN&gt;"ADMIN_surface"&lt;/SPAN&gt;:&lt;BR /&gt;        arcpy.CalculateField_management(fc&lt;SPAN&gt;, &lt;/SPAN&gt;fieldnm&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'!Name1!'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;exp_type)&lt;BR /&gt;    &lt;SPAN&gt;elif &lt;/SPAN&gt;fc == &lt;SPAN&gt;"PLANNING_WAY"&lt;/SPAN&gt;:&lt;BR /&gt;        expression = &lt;SPAN&gt;"calc(!QSTRM!, !LLD!)"&lt;BR /&gt;&lt;/SPAN&gt;        codeblock = &lt;SPAN&gt;"""&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;        def calc(QSTRM, LLD)&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;            if LLD is None:&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;                return QSTRM&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;        else:&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;        return QSTRM + " " + LLD&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;        """&lt;BR /&gt;&lt;/SPAN&gt;        arcpy.CalculateField_management(fc&lt;SPAN&gt;, &lt;/SPAN&gt;fieldnm&lt;SPAN&gt;, &lt;/SPAN&gt;expression&lt;SPAN&gt;, &lt;/SPAN&gt;exp_type&lt;SPAN&gt;, &lt;/SPAN&gt;codeblock)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong with this code? I am running this in PyCharm.&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2022 22:27:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/beginner-python-code-questions/m-p/1190644#M57047</guid>
      <dc:creator>CarolynGao15</dc:creator>
      <dc:date>2022-07-07T22:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner Python Code Questions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/beginner-python-code-questions/m-p/1190682#M57052</link>
      <description>&lt;PRE&gt;&lt;SPAN&gt;return QSTRM + " " + LLD&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;needs to be indented 4 spaces.&lt;/P&gt;&lt;P&gt;also&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;a, b = None, None  # two fields one or both with None in them
# concatenate with _

f'{a}_{b}'
'None_None'

# hence, no need to check for None when converting to string format&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 07 Jul 2022 23:22:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/beginner-python-code-questions/m-p/1190682#M57052</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-07-07T23:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner Python Code Questions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/beginner-python-code-questions/m-p/1190683#M57053</link>
      <description>&lt;P&gt;One thing you can try is checking if the code block is causing issues. You can replace the block with this 1-line expression:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;"{} {}".format(!QSTRM!, !LLD!) if !LLD! is not None else !QSTRM!&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2022 23:25:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/beginner-python-code-questions/m-p/1190683#M57053</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2022-07-07T23:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner Python Code Questions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/beginner-python-code-questions/m-p/1190835#M57068</link>
      <description>&lt;P&gt;Thank you so much! This worked perfectly and cut down a whole block of code lol!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 15:02:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/beginner-python-code-questions/m-p/1190835#M57068</guid>
      <dc:creator>CarolynGao15</dc:creator>
      <dc:date>2022-07-08T15:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner Python Code Questions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/beginner-python-code-questions/m-p/1190837#M57069</link>
      <description>&lt;P&gt;Thank you! I completely missed that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don't mind, could you explain the second part?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would I plug that in to the expression part of my arcpy.management.CalculateField line?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 15:04:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/beginner-python-code-questions/m-p/1190837#M57069</guid>
      <dc:creator>CarolynGao15</dc:creator>
      <dc:date>2022-07-08T15:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: Beginner Python Code Questions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/beginner-python-code-questions/m-p/1190922#M57084</link>
      <description>&lt;LI-CODE lang="python"&gt;# given two variables, a and b, or fields if denoted by !a! and !b!
# if either of them are None, convert them to their string representation
# using python's mini format syntax, which converts any object to string

f'{a}_{b}'
'None_None'

# you can do condition checking and provide alternate formatting.
# note.... remove the _ if you don't want it to appear in the output

a, b = None, None
f"{'' if a is None else a}_{'' if b is None else b}"
'_'

a, b = None, "Something"
f"{'' if a is None else a}_{'' if b is None else b}"
'_Something'&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 08 Jul 2022 17:25:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/beginner-python-code-questions/m-p/1190922#M57084</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-07-08T17:25:11Z</dc:date>
    </item>
  </channel>
</rss>

