<?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: Replace string in field attribute in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81906#M6546</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just FYI, this works as the expression in ArcGIS 10, SP2: &lt;/SPAN&gt;&lt;STRONG&gt;!Hyperlink!.replace("originalstring","replacewiththis")&lt;/STRONG&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Apr 2012 14:47:00 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2012-04-20T14:47:00Z</dc:date>
    <item>
      <title>Replace string in field attribute</title>
      <link>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81901#M6541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In ArcGIS 9.x was in the options..., Find and Replace. In ArcGIS 10.x, we have to use Python script !FieldName!.replace("OldText", "NewText")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I may be missing something here, but why on earth the Python script is not working? Here is what I type in the Expression:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!Hyperlink!.replace("Dec20112", "Dec2011")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;, and here is the message from the Geoprocessing results:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000539: &amp;lt;type 'exceptions.SyntaxError'&amp;gt;: invalid syntax (&amp;lt;expression&amp;gt;, line 1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (CalculateField).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have managed to do the replacing with VBscript: Replace ([Hyperlink], "Dec20112", "Dec2011")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any idea about what may be wrong with Python here? It says PYTHON 9.3; I'm running ArcGIS10sp4 under Win7-64bit.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Niko&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2012 10:54:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81901#M6541</guid>
      <dc:creator>NikolaosGaliatsatos</dc:creator>
      <dc:date>2012-04-20T10:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string in field attribute</title>
      <link>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81902#M6542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In ArcGIS10 there's Find&amp;amp;Replace funcion when you browse Attribute Table:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]13694[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;To be able to replace something, you have to be in edit session.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;BTW I've no idea why .replace() do not work for you. I've made some test and it worked even for field with Date type.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2012 11:28:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81902#M6542</guid>
      <dc:creator>MarcinGasior</dc:creator>
      <dc:date>2012-04-20T11:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string in field attribute</title>
      <link>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81903#M6543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, I am in the Edit session (I tried both in and outside the Edit session). I even tried the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Block:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import re&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;def replace(value):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; return re.sub ('Dec20112', 'Dec2011', value)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;replace(!Hyperlink!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;which did not work either. I'm not a Python expert, but shouldn't this work?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, "Find and Replace" is there..., for some reason (frustration for Python not working perhaps?) I didn't see it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2012 12:09:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81903#M6543</guid>
      <dc:creator>NikolaosGaliatsatos</dc:creator>
      <dc:date>2012-04-20T12:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string in field attribute</title>
      <link>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81904#M6544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think the issue with the python is that .replace() is a string function and it looks to me like you're trying to apply it to the field name.&amp;nbsp; I don't know for sure without playing with your code, but I imagine that you would need an updateCursor and then set the fieldValue = fieldValue.replace()&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2012 14:05:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81904#M6544</guid>
      <dc:creator>RyanForbes1</dc:creator>
      <dc:date>2012-04-20T14:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string in field attribute</title>
      <link>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81905#M6545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think the issue with the python is that .replace() is a string function and it looks to me like you're trying to apply it to the field name. I don't know for sure without playing with your code, but I imagine that you would need an updateCursor and then set the fieldValue = fieldValue.replace()&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2012 14:09:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81905#M6545</guid>
      <dc:creator>RyanForbes1</dc:creator>
      <dc:date>2012-04-20T14:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string in field attribute</title>
      <link>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81906#M6546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just FYI, this works as the expression in ArcGIS 10, SP2: &lt;/SPAN&gt;&lt;STRONG&gt;!Hyperlink!.replace("originalstring","replacewiththis")&lt;/STRONG&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2012 14:47:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81906#M6546</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2012-04-20T14:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string in field attribute</title>
      <link>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81907#M6547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Many thanks for your responses.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm going through the Python training of ESRI right now, and it seems there is some problem with Python in ArcGIS (could it be the installation in my machine?). For example, I'm trying to run this piece of code in Field Calculator:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def label(name, type):
 if type == "HIGH":
&amp;nbsp; return name + " HS"
 elif type == "MIDDLE":
&amp;nbsp; return name + " MS"
 elif type == "ELEMENTARY":
&amp;nbsp; return name + " ELEM"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;with Expression:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;label( !NAME!, !TYPE! )&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and I'm receiving a 999999 error. Even if I put the code that the ESRI training is providing (.cal file), the same error comes up.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry to bother you guys with this..., nothing to do with programming..., just the usual ArcGIS bugs.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:08:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81907#M6547</guid>
      <dc:creator>NikolaosGaliatsatos</dc:creator>
      <dc:date>2021-12-10T23:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string in field attribute</title>
      <link>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81908#M6548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think 'type' is a reserved word. Try replacing it with a different variable name.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2012 17:03:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81908#M6548</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2012-04-20T17:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string in field attribute</title>
      <link>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81909#M6549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Following the advice of the ESRI people, I called the Administrator to run a "repair" for the ArcGIS Desktop installation. This fixed all issues and the described code worked.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Many thanks to all for your helpful comments.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Apr 2012 15:32:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81909#M6549</guid>
      <dc:creator>NikolaosGaliatsatos</dc:creator>
      <dc:date>2012-04-23T15:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string in field attribute</title>
      <link>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81910#M6550</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;It is fairly simple. Try this one. It works for me perfectly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;replace([Field_Name],"oldtextToFind","NewText")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Mar 2014 17:20:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replace-string-in-field-attribute/m-p/81910#M6550</guid>
      <dc:creator>UsmanYousaf1</dc:creator>
      <dc:date>2014-03-05T17:20:47Z</dc:date>
    </item>
  </channel>
</rss>

