<?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 Calculate Field problem Please Help in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculate-field-problem-please-help/m-p/274519#M21215</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've written a script that narrows down a selection of points (cities) and then adds a field called CITYNAME to the feature class.&amp;nbsp; I need to update the new CITYNAME field with the same values as the NAME field in the same feature class but it doesn't update them although it shows as having run successfully.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to do this so that I can spatially join this points (cities) dataset to polygons (counties) and lines (roads) because all three of them have the same fieldname called NAME.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using ArcGIS v10.0 and any help would be appreciated as I've tried various methods like CalculateField and UpdateCursor to no avail.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Scotaidh&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
# ExtractFeaturesByLocationAndAttribute.py EFLA.py
# Description: Extract features to a new feature class based on a Location and an attribute query
# then add field called CITYNAME and update it with the NAME field from the cities layer

# import system modules
import arcpy
from arcpy import env
import os

# set overwrite option
arcpy.env.overwriteOutput = True

# Put in error trapping in case an error occurs when running tool
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make a layer from the cities feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("H:/working/Findsites.gdb/cities","citiesL")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select all cities that are within 30km of an interstate
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("citiesL", "WITHIN_A_DISTANCE", "H:/working/Findsites.gdb/interstates", "30 KILOMETERS", "NEW_SELECTION")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Within the selection (done above) further select only those cities that have a university and low crime rate
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("citiesL", "SUBSET_SELECTION", "UNIVERSITY = 1 AND CRIME_INDE &amp;lt;= 0.02")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make a layer from the counties feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("H://working/Findsites.gdb/counties","countiesL")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # From the counties layer select only those counties with a large enough workforce and number of farms
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("countiesL", "NEW_SELECTION", "AGE_18_64 &amp;gt;= 25000 AND NO_FARMS87 &amp;gt;= 500")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select all cities that intersect counties that meet work force and number of farms criteria
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("citiesL", "INTERSECT", "countiesL", "", "SUBSET_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Write the selected features to a new featureclass
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management("citiesL", "H:/working/Findsites.gdb/CityList")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # create a new field called CITYNAME to replace NAME because other datasets have a NAME field
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management("H:/working/Findsites.gdb/CityList", "CITYNAME", "TEXT", "", "", "25")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; expression1 = '!MP_VAL!'
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(CityList, CITYNAME, expression1, "PYTHON", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Calculate Field - update new CITYNAME field with NAME field
&amp;nbsp;&amp;nbsp;&amp;nbsp; # arcpy.AddMessage("Calculating Updated Field...")
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Expression = "'{0}'".format(arcpy.GetValue(NAME))
&amp;nbsp;&amp;nbsp;&amp;nbsp; # single quoted string literal
&amp;nbsp;&amp;nbsp;&amp;nbsp; # arcpy.CalculateField_management(CityList, CITYNAME, Expression, "PYTHON")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # If an error occurred print the message to the screen
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 04 Apr 2013 16:06:02 GMT</pubDate>
    <dc:creator>ScottMacDonald</dc:creator>
    <dc:date>2013-04-04T16:06:02Z</dc:date>
    <item>
      <title>Calculate Field problem Please Help</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-problem-please-help/m-p/274519#M21215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've written a script that narrows down a selection of points (cities) and then adds a field called CITYNAME to the feature class.&amp;nbsp; I need to update the new CITYNAME field with the same values as the NAME field in the same feature class but it doesn't update them although it shows as having run successfully.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to do this so that I can spatially join this points (cities) dataset to polygons (counties) and lines (roads) because all three of them have the same fieldname called NAME.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using ArcGIS v10.0 and any help would be appreciated as I've tried various methods like CalculateField and UpdateCursor to no avail.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Scotaidh&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
# ExtractFeaturesByLocationAndAttribute.py EFLA.py
# Description: Extract features to a new feature class based on a Location and an attribute query
# then add field called CITYNAME and update it with the NAME field from the cities layer

# import system modules
import arcpy
from arcpy import env
import os

# set overwrite option
arcpy.env.overwriteOutput = True

# Put in error trapping in case an error occurs when running tool
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make a layer from the cities feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("H:/working/Findsites.gdb/cities","citiesL")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select all cities that are within 30km of an interstate
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("citiesL", "WITHIN_A_DISTANCE", "H:/working/Findsites.gdb/interstates", "30 KILOMETERS", "NEW_SELECTION")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Within the selection (done above) further select only those cities that have a university and low crime rate
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("citiesL", "SUBSET_SELECTION", "UNIVERSITY = 1 AND CRIME_INDE &amp;lt;= 0.02")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make a layer from the counties feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("H://working/Findsites.gdb/counties","countiesL")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # From the counties layer select only those counties with a large enough workforce and number of farms
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("countiesL", "NEW_SELECTION", "AGE_18_64 &amp;gt;= 25000 AND NO_FARMS87 &amp;gt;= 500")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select all cities that intersect counties that meet work force and number of farms criteria
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("citiesL", "INTERSECT", "countiesL", "", "SUBSET_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Write the selected features to a new featureclass
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management("citiesL", "H:/working/Findsites.gdb/CityList")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # create a new field called CITYNAME to replace NAME because other datasets have a NAME field
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management("H:/working/Findsites.gdb/CityList", "CITYNAME", "TEXT", "", "", "25")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; expression1 = '!MP_VAL!'
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(CityList, CITYNAME, expression1, "PYTHON", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Calculate Field - update new CITYNAME field with NAME field
&amp;nbsp;&amp;nbsp;&amp;nbsp; # arcpy.AddMessage("Calculating Updated Field...")
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Expression = "'{0}'".format(arcpy.GetValue(NAME))
&amp;nbsp;&amp;nbsp;&amp;nbsp; # single quoted string literal
&amp;nbsp;&amp;nbsp;&amp;nbsp; # arcpy.CalculateField_management(CityList, CITYNAME, Expression, "PYTHON")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # If an error occurred print the message to the screen
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Apr 2013 16:06:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-problem-please-help/m-p/274519#M21215</guid>
      <dc:creator>ScottMacDonald</dc:creator>
      <dc:date>2013-04-04T16:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field problem Please Help</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-problem-please-help/m-p/274520#M21216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Do you have to do it with a script?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just click on the new column and use the field calculator.&amp;nbsp; Take a few seconds.&amp;nbsp; Also depending on your environment it may not update them outside of an edit session. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I've written a script that narrows down a selection of points (cities) and then adds a field called CITYNAME to the feature class.&amp;nbsp; I need to update the new CITYNAME field with the same values as the NAME field in the same feature class but it doesn't update them although it shows as having run successfully.&lt;BR /&gt;&lt;BR /&gt;I need to do this so that I can spatially join this points (cities) dataset to polygons (counties) and lines (roads) because all three of them have the same fieldname called NAME.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;I'm using ArcGIS v10.0 and any help would be appreciated as I've tried various methods like CalculateField and UpdateCursor to no avail.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Scotaidh&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# ExtractFeaturesByLocationAndAttribute.py EFLA.py
# Description: Extract features to a new feature class based on a Location and an attribute query
# then add field called CITYNAME and update it with the NAME field from the cities layer

# import system modules
import arcpy
from arcpy import env
import os

# set overwrite option
arcpy.env.overwriteOutput = True

# Put in error trapping in case an error occurs when running tool
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make a layer from the cities feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("H:/working/Findsites.gdb/cities","citiesL")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select all cities that are within 30km of an interstate
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("citiesL", "WITHIN_A_DISTANCE", "H:/working/Findsites.gdb/interstates", "30 KILOMETERS", "NEW_SELECTION")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Within the selection (done above) further select only those cities that have a university and low crime rate
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("citiesL", "SUBSET_SELECTION", "UNIVERSITY = 1 AND CRIME_INDE &amp;lt;= 0.02")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make a layer from the counties feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("H://working/Findsites.gdb/counties","countiesL")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # From the counties layer select only those counties with a large enough workforce and number of farms
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("countiesL", "NEW_SELECTION", "AGE_18_64 &amp;gt;= 25000 AND NO_FARMS87 &amp;gt;= 500")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select all cities that intersect counties that meet work force and number of farms criteria
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("citiesL", "INTERSECT", "countiesL", "", "SUBSET_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Write the selected features to a new featureclass
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management("citiesL", "H:/working/Findsites.gdb/CityList")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # create a new field called CITYNAME to replace NAME because other datasets have a NAME field
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management("H:/working/Findsites.gdb/CityList", "CITYNAME", "TEXT", "", "", "25")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; expression1 = '!MP_VAL!'
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(CityList, CITYNAME, expression1, "PYTHON", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Calculate Field - update new CITYNAME field with NAME field
&amp;nbsp;&amp;nbsp;&amp;nbsp; # arcpy.AddMessage("Calculating Updated Field...")
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Expression = "'{0}'".format(arcpy.GetValue(NAME))
&amp;nbsp;&amp;nbsp;&amp;nbsp; # single quoted string literal
&amp;nbsp;&amp;nbsp;&amp;nbsp; # arcpy.CalculateField_management(CityList, CITYNAME, Expression, "PYTHON")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # If an error occurred print the message to the screen
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:23:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-problem-please-help/m-p/274520#M21216</guid>
      <dc:creator>RobertBorchert</dc:creator>
      <dc:date>2021-12-11T13:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field problem Please Help</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-problem-please-help/m-p/274521#M21217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You need to put quotes around "CITYNAME" since it is text and not a variable. So instead of:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_management(CityList, CITYNAME, expression1, "PYTHON", "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it needs to be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_management(CityList, "CITYNAME", expression1, "PYTHON", "")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Apr 2013 17:23:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-problem-please-help/m-p/274521#M21217</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2013-04-04T17:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field problem Please Help</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-problem-please-help/m-p/274522#M21218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Chris for your quick reply. I changed CityList to "CityList" (code below) but it still doesn't update the new CITYNAME field with the NAME field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you perhaps have any other suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# ExtractFeaturesByLocationAndAttribute.py EFLA.py
# Description: Extract features to a new feature class based on a Location and an attribute query
# then add field called CITYNAME and update it with the NAME field from the cities layer

# import system modules
import arcpy
from arcpy import env
import os

# set overwrite option
arcpy.env.overwriteOutput = True

# Put in error trapping in case an error occurs when running tool
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make a layer from the cities feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("H:/working/Findsites.gdb/cities","citiesL")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select all cities that are within 30km of an interstate
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("citiesL", "WITHIN_A_DISTANCE", "H:/working/Findsites.gdb/interstates", "30 KILOMETERS", "NEW_SELECTION")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Within the selection (done above) further select only those cities that have a university and low crime rate
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("citiesL", "SUBSET_SELECTION", "UNIVERSITY = 1 AND CRIME_INDE &amp;lt;= 0.02")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make a layer from the counties feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("H://working/Findsites.gdb/counties","countiesL")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # From the counties layer select only those counties with a large enough workforce and number of farms
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("countiesL", "NEW_SELECTION", "AGE_18_64 &amp;gt;= 25000 AND NO_FARMS87 &amp;gt;= 500")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select all cities that intersect counties that meet work force and number of farms criteria
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("citiesL", "INTERSECT", "countiesL", "", "SUBSET_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Write the selected features to a new featureclass
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management("citiesL", "H:/working/Findsites.gdb/CityList")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # create a new field called CITYNAME to replace NAME because other datasets have a NAME field
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management("H:/working/Findsites.gdb/CityList", "CITYNAME", "TEXT", "", "", "25")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; expression1 = '!NAME!'
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(CityList, "CITYNAME", expression1, "PYTHON") 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # If an error occurred print the message to the screen
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:23:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-problem-please-help/m-p/274522#M21218</guid>
      <dc:creator>ScottMacDonald</dc:creator>
      <dc:date>2021-12-11T13:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field problem Please Help</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-problem-please-help/m-p/274523#M21219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Chris for your quick reply.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I put quotes around "CITYNAME" but the field still does not update with the NAME field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The edited code is shown below and I wondered if you had any other ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Scott&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# ExtractFeaturesByLocationAndAttribute.py EFLA.py
# Description: Extract features to a new feature class based on a Location and an attribute query
# then add field called CITYNAME and update it with the NAME field from the cities layer

# import system modules
import arcpy
from arcpy import env
import os

# set overwrite option
arcpy.env.overwriteOutput = True

# Put in error trapping in case an error occurs when running tool
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make a layer from the cities feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("H:/working/Findsites.gdb/cities","citiesL")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select all cities that are within 30km of an interstate
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("citiesL", "WITHIN_A_DISTANCE", "H:/working/Findsites.gdb/interstates", "30 KILOMETERS", "NEW_SELECTION")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Within the selection (done above) further select only those cities that have a university and low crime rate
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("citiesL", "SUBSET_SELECTION", "UNIVERSITY = 1 AND CRIME_INDE &amp;lt;= 0.02")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make a layer from the counties feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("H://working/Findsites.gdb/counties","countiesL")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # From the counties layer select only those counties with a large enough workforce and number of farms
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("countiesL", "NEW_SELECTION", "AGE_18_64 &amp;gt;= 25000 AND NO_FARMS87 &amp;gt;= 500")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select all cities that intersect counties that meet work force and number of farms criteria
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("citiesL", "INTERSECT", "countiesL", "", "SUBSET_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Write the selected features to a new featureclass
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management("citiesL", "H:/working/Findsites.gdb/CityList")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # create a new field called CITYNAME to replace NAME because other datasets have a NAME field
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management("H:/working/Findsites.gdb/CityList", "CITYNAME", "TEXT", "", "", "25")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; expression1 = '!NAME!'
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(CityList, "CITYNAME", expression1, "PYTHON") 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # If an error occurred print the message to the screen
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:23:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-problem-please-help/m-p/274523#M21219</guid>
      <dc:creator>ScottMacDonald</dc:creator>
      <dc:date>2021-12-11T13:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field problem Please Help</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-problem-please-help/m-p/274524#M21220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your script has some issues with strings vs. variables and also how you are defining paths. For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. In Python, cityList is not the same thing as 'cityList'.... the 1st referes to a variable since it isn't in quotes, but the second is a string object since it is in quotes&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Python is picky how you define paths. All of these are okay:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;path = r"H:\here\it\is"
path = "H:\\here\\it\is"
path = "H:/here/it/is"&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;This is not okay though:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;path = "H://here//it//is"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I took the liberty to rewrite your code. Notice how the FCs are defined as variables up near the top, and they use a consistent path delimiter method. This code "should" work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os, sys, traceback. arcpy
arcpy.env.overwriteOutput = True
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; citiesFC = r"H:\working\Findsites.gdb\cities"
&amp;nbsp;&amp;nbsp;&amp;nbsp; interstatesFC = r"H:\working\Findsites.gdb\interstates"
&amp;nbsp;&amp;nbsp;&amp;nbsp; countiesFC = r"H:\working\Findsites.gdb\counties"
&amp;nbsp;&amp;nbsp;&amp;nbsp; cityListFC = r"H:\working\Findsites.gdb\city_list"
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(citiesFC,"citiesL")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("citiesL", "WITHIN_A_DISTANCE", interstatesFC, "30 KILOMETERS", "NEW_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("citiesL", "SUBSET_SELECTION", "UNIVERSITY = 1 AND CRIME_INDE &amp;lt;= 0.02")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(countiesFC,"countiesL")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("countiesL", "NEW_SELECTION", "AGE_18_64 &amp;gt;= 25000 AND NO_FARMS87 &amp;gt;= 500")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("citiesL", "INTERSECT", "countiesL", "", "SUBSET_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management("citiesL", cityListFC)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(cityListFC, "CITYNAME", "TEXT", "", "", "25")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(cityListFC, "CITYNAME", "!NAME!", "PYTHON")&amp;nbsp; 
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\n*** LAST GEOPROCESSOR MESSAGE (may not be source of the error)***"; print arcpy.GetMessages()
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Python Error Info: " +&amp;nbsp; str(sys.exc_type)+ ": " + str(sys.exc_value)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:23:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-problem-please-help/m-p/274524#M21220</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T13:23:53Z</dc:date>
    </item>
  </channel>
</rss>

