<?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 Field values with trailing BackSlash Kills the Python for gp.CalculateField (v9.3) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-values-with-trailing-backslash-kills-the/m-p/297090#M22973</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think that gp.CalculateField does not work if the field value has a backslash (\) or a quote (')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to strip (Trim) and Replace for each field value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This was easy using VB but now it's difficult in Python. I'm now required to use Python because ESRI told us not to use .NET&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;outstr = instr.replace('|',' ').strip()\n\&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;*******************************&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't think the codeblock is a problem because it does not appear to get that far before the error message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; "fixvalue(str(!Field!))" (errror seems to be on this statement) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; "fixvalue(str(\"|\")"&amp;nbsp; (appears like this in the error message)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;expr = "fixvalue(str(!Field!))"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;codeblock = "def fixvalue(instr):\n\&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outstr = instr.replace('|',' ').strip()\n\&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return outstr"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CalculateField_management(FeaClass, "Field", expr, "PYTHON", codeblock)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 09 Dec 2011 14:25:48 GMT</pubDate>
    <dc:creator>BillMiller</dc:creator>
    <dc:date>2011-12-09T14:25:48Z</dc:date>
    <item>
      <title>Field values with trailing BackSlash Kills the Python for gp.CalculateField (v9.3)</title>
      <link>https://community.esri.com/t5/python-questions/field-values-with-trailing-backslash-kills-the/m-p/297090#M22973</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think that gp.CalculateField does not work if the field value has a backslash (\) or a quote (')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to strip (Trim) and Replace for each field value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This was easy using VB but now it's difficult in Python. I'm now required to use Python because ESRI told us not to use .NET&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;outstr = instr.replace('|',' ').strip()\n\&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;*******************************&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't think the codeblock is a problem because it does not appear to get that far before the error message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; "fixvalue(str(!Field!))" (errror seems to be on this statement) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; "fixvalue(str(\"|\")"&amp;nbsp; (appears like this in the error message)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;expr = "fixvalue(str(!Field!))"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;codeblock = "def fixvalue(instr):\n\&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outstr = instr.replace('|',' ').strip()\n\&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return outstr"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CalculateField_management(FeaClass, "Field", expr, "PYTHON", codeblock)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Dec 2011 14:25:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-values-with-trailing-backslash-kills-the/m-p/297090#M22973</guid>
      <dc:creator>BillMiller</dc:creator>
      <dc:date>2011-12-09T14:25:48Z</dc:date>
    </item>
  </channel>
</rss>

