<?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 Replacing text in txt files in Python Snippets Questions</title>
    <link>https://community.esri.com/t5/python-snippets-questions/replacing-text-in-txt-files/m-p/800833#M240</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am replacing square brackets by round brackets with help of a python script - works perfectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I also want to replace a single word by another word (Cruise -&amp;gt; Campaign): nothing happens.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the part of the script:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;r &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; csv&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;reader&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;t&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; delimiter&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"\t"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
all&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

header&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;r&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;next&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;#arcpy.AddMessage(header)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; fields &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; header&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
fields&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;replace&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Cruise"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Campaign"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="comment token"&gt;##not working&lt;/SPAN&gt;
fields&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;replace&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"["&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"("&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
fields&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;replace&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"]"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;")"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any idea why it replaces the brackets fine but not the word?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 09:17:01 GMT</pubDate>
    <dc:creator>Nicole_Ueberschär</dc:creator>
    <dc:date>2021-12-12T09:17:01Z</dc:date>
    <item>
      <title>Replacing text in txt files</title>
      <link>https://community.esri.com/t5/python-snippets-questions/replacing-text-in-txt-files/m-p/800833#M240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am replacing square brackets by round brackets with help of a python script - works perfectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I also want to replace a single word by another word (Cruise -&amp;gt; Campaign): nothing happens.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the part of the script:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;r &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; csv&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;reader&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;t&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; delimiter&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"\t"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
all&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

header&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;r&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;next&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;#arcpy.AddMessage(header)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; fields &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; header&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
fields&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;replace&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Cruise"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Campaign"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="comment token"&gt;##not working&lt;/SPAN&gt;
fields&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;replace&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"["&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"("&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
fields&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;replace&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"]"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;")"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any idea why it replaces the brackets fine but not the word?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:17:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/replacing-text-in-txt-files/m-p/800833#M240</guid>
      <dc:creator>Nicole_Ueberschär</dc:creator>
      <dc:date>2021-12-12T09:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing text in txt files</title>
      <link>https://community.esri.com/t5/python-snippets-questions/replacing-text-in-txt-files/m-p/800834#M241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;post the line in question... the details will be found there.&lt;/P&gt;&lt;P&gt;case-sensitivity needs to be considered as well&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addendum&lt;/P&gt;&lt;P&gt;As a followup, I had assumed you were trying to replace the field name with a new value, I suspect that you want to replace the values in the csv file with the new value.&lt;/P&gt;&lt;P&gt;I would suggest that converting it to a featureclass, then use the calculate field tool (accessed through your script) to perform the conversion.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Sep 2017 19:21:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/replacing-text-in-txt-files/m-p/800834#M241</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-09-15T19:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing text in txt files</title>
      <link>https://community.esri.com/t5/python-snippets-questions/replacing-text-in-txt-files/m-p/800835#M242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dan,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to work with txt files.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both, the brackets and the word "Cruise" are only to find in the header of the txt file(s).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I was trying it in the wrong place. Obviously I had the lines below already in a different position in my script (except of the Cruise line) which worked and the one I posted above didn't do anything. So when I added now the Cruise replacement it worked.&amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt; &lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; open&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;tablefile&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'r'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; txtfile&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; txtdata&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;txtfile&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;read&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 txtdata&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;txtdata&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;replace&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"["&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"("&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 txtdata&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;txtdata&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;replace&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"]"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;")"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 txtdata&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;txtdata&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;replace&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Cruise"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Campaign"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; open&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;tablefile&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'w'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; txtfile&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; txtfile&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;write&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;txtdata&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I knew it must have been my mistake...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:17:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/replacing-text-in-txt-files/m-p/800835#M242</guid>
      <dc:creator>Nicole_Ueberschär</dc:creator>
      <dc:date>2021-12-12T09:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing text in txt files</title>
      <link>https://community.esri.com/t5/python-snippets-questions/replacing-text-in-txt-files/m-p/800836#M243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, it helps to post the full script... it is the only way that people know what you are working with&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Sep 2017 18:40:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/replacing-text-in-txt-files/m-p/800836#M243</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-09-16T18:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing text in txt files</title>
      <link>https://community.esri.com/t5/python-snippets-questions/replacing-text-in-txt-files/m-p/800837#M244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure if it would really help to post the full 250 lines of my script...&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Sep 2017 22:07:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/replacing-text-in-txt-files/m-p/800837#M244</guid>
      <dc:creator>Nicole_Ueberschär</dc:creator>
      <dc:date>2017-09-16T22:07:39Z</dc:date>
    </item>
  </channel>
</rss>

