<?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 Python CalculateField sometimes doesn't work depending on field value variable in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48396#M3833</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to add and calculate a text field in an existing dbf table by using a variable to set the value of the field. The AddField code is working fine. The CalculateField code sometimes does not work depending on the value of the variable I'm using to calculate the field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My statements (inside a for loop) to add and calculate the field are:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for ascii in rasterList:[INDENT]outTable = r'D:\test.dbf'[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]dateField = 'Date'[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]fieldLength = 20[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]part = os.path.split(ascii)[1][/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]fieldValue = os.path.splitext(part)[0][/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]arcpy.AddField_management(outTable, dateField, "TEXT", "", "", fieldLength)[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]arcpy.CalculateField_management(outTable, dateField, fieldValue)[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I set fieldValue = os.path.splitext(part)[0], it does not work--the field remains blank. If I print fieldValue, I get ECR_TXT_201304, which is correct--it's what I want stored in the Date field for all records in the table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If I set fieldValue = "201304", it works--the Date field gets populated with 201304.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I even tried fieldValue = str(os.path.splitext(part)[0]), and that didn't work either.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I never get any error messages, the script runs without any indication of a problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm baffled at this point why this code doesn't work when using the os.path variable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for any help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 30 Dec 2013 21:28:44 GMT</pubDate>
    <dc:creator>PamFroemke</dc:creator>
    <dc:date>2013-12-30T21:28:44Z</dc:date>
    <item>
      <title>Python CalculateField sometimes doesn't work depending on field value variable</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48396#M3833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to add and calculate a text field in an existing dbf table by using a variable to set the value of the field. The AddField code is working fine. The CalculateField code sometimes does not work depending on the value of the variable I'm using to calculate the field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My statements (inside a for loop) to add and calculate the field are:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for ascii in rasterList:[INDENT]outTable = r'D:\test.dbf'[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]dateField = 'Date'[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]fieldLength = 20[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]part = os.path.split(ascii)[1][/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]fieldValue = os.path.splitext(part)[0][/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]arcpy.AddField_management(outTable, dateField, "TEXT", "", "", fieldLength)[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]arcpy.CalculateField_management(outTable, dateField, fieldValue)[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I set fieldValue = os.path.splitext(part)[0], it does not work--the field remains blank. If I print fieldValue, I get ECR_TXT_201304, which is correct--it's what I want stored in the Date field for all records in the table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If I set fieldValue = "201304", it works--the Date field gets populated with 201304.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I even tried fieldValue = str(os.path.splitext(part)[0]), and that didn't work either.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I never get any error messages, the script runs without any indication of a problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm baffled at this point why this code doesn't work when using the os.path variable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for any help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Dec 2013 21:28:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48396#M3833</guid>
      <dc:creator>PamFroemke</dc:creator>
      <dc:date>2013-12-30T21:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: Python CalculateField sometimes doesn't work depending on field value variable</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48397#M3834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I'm trying to add and calculate a text field in an existing dbf table by using a variable to set the value of the field. The AddField code is working fine. The CalculateField code sometimes does not work depending on the value of the variable I'm using to calculate the field.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;My statements (inside a for loop) to add and calculate the field are:&lt;BR /&gt;for ascii in rasterList:[INDENT]outTable = r'D:\test.dbf'[/INDENT]&lt;BR /&gt;[INDENT]dateField = 'Date'[/INDENT]&lt;BR /&gt;[INDENT]fieldLength = 20[/INDENT]&lt;BR /&gt;[INDENT]part = os.path.split(ascii)[1][/INDENT]&lt;BR /&gt;[INDENT]fieldValue = os.path.splitext(part)[0][/INDENT]&lt;BR /&gt;[INDENT]arcpy.AddField_management(outTable, dateField, "TEXT", "", "", fieldLength)[/INDENT]&lt;BR /&gt;[INDENT]arcpy.CalculateField_management(outTable, dateField, fieldValue)[/INDENT]&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If I set fieldValue = os.path.splitext(part)[0], it does not work--the field remains blank. If I print fieldValue, I get ECR_TXT_201304, which is correct--it's what I want stored in the Date field for all records in the table.&lt;BR /&gt;If I set fieldValue = "201304", it works--the Date field gets populated with 201304.&lt;BR /&gt;I even tried fieldValue = str(os.path.splitext(part)[0]), and that didn't work either.&lt;BR /&gt;I never get any error messages, the script runs without any indication of a problem.&lt;BR /&gt;&lt;BR /&gt;I'm baffled at this point why this code doesn't work when using the os.path variable.&lt;BR /&gt;Thank you for any help!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It is a very bad practice to name a field with a key word like 'Date'.&amp;nbsp; I am surprised it even accepts that field name.&amp;nbsp; That field name is bound to cause strange behaviors.&amp;nbsp; Name the field something that qualifies the word Date as the first step (Mod_Date, Created, etc.).&amp;nbsp; If for some reason the field believes it is a real date field, the all numeric text would work (since the text can be parsed to a number and internally dates are converted to numbers anyway), but any actual text that is not compatible with a true date parsing would fail.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Dec 2013 22:50:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48397#M3834</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2013-12-30T22:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Python CalculateField sometimes doesn't work depending on field value variable</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48398#M3835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Richard, thank you for your reply. I changed the field name to 'EDDI_Date'. Then I tested with fieldValue set to 'EDDI_ETrc_201300'. This did not work--the field remained blank. If I set fieldValue to '201300', then the field gets populated. It's like the field is not defined as a TEXT field.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Dec 2013 12:56:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48398#M3835</guid>
      <dc:creator>PamFroemke</dc:creator>
      <dc:date>2013-12-31T12:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: Python CalculateField sometimes doesn't work depending on field value variable</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48399#M3836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;did you try str(fieldvalue) in your calculatefield expression?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Dec 2013 13:17:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48399#M3836</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2013-12-31T13:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Python CalculateField sometimes doesn't work depending on field value variable</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48400#M3837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Dan. I did try that and got the same response--the field was left blank.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Dec 2013 13:19:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48400#M3837</guid>
      <dc:creator>PamFroemke</dc:creator>
      <dc:date>2013-12-31T13:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python CalculateField sometimes doesn't work depending on field value variable</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48401#M3838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;just to be sure on something....the table is completely closed when you run your script, and when you open it, it is empty?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Dec 2013 13:22:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48401#M3838</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2013-12-31T13:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: Python CalculateField sometimes doesn't work depending on field value variable</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48402#M3839</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, that's correct, the tables are closed. I'm using Excel to view the dbf outputs, then closing them again before I run the script. ArcMap and ArcCatalog are also closed.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Dec 2013 13:24:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48402#M3839</guid>
      <dc:creator>PamFroemke</dc:creator>
      <dc:date>2013-12-31T13:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Python CalculateField sometimes doesn't work depending on field value variable</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48403#M3840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;try viewing the tables in ArcMap....also put "hello" in the calculatefield expression to rule out something else further up the line&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Dec 2013 13:36:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48403#M3840</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2013-12-31T13:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python CalculateField sometimes doesn't work depending on field value variable</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48404#M3841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dan, I can't even get that to work. My code line is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_management(outTable, dateField, "hello")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_management(outTable, dateField, "123")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the field is populated with 123.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm checking the tables with ArcMap, then closing it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Dec 2013 14:34:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48404#M3841</guid>
      <dc:creator>PamFroemke</dc:creator>
      <dc:date>2013-12-31T14:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: Python CalculateField sometimes doesn't work depending on field value variable</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48405#M3842</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Now I've tried:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldValue = chr(34) &amp;amp; os.path.splitext(part)[0] &amp;amp; chr(34)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and got an error, TypeError: unsupported operand type(s) for &amp;amp;: 'str' and 'str'.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Dec 2013 14:49:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48405#M3842</guid>
      <dc:creator>PamFroemke</dc:creator>
      <dc:date>2013-12-31T14:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Python CalculateField sometimes doesn't work depending on field value variable</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48406#M3843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sol, your solution with the "+" symbols worked. Not sure why the syntax has to be this cumbersome. Seems like I used to be able to use syntax like my original script. I guess this is the new and "improved" Python?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, everyone, for the help!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Dec 2013 15:20:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-sometimes-doesn-t-work/m-p/48406#M3843</guid>
      <dc:creator>PamFroemke</dc:creator>
      <dc:date>2013-12-31T15:20:03Z</dc:date>
    </item>
  </channel>
</rss>

