How to replace words in file?
<p>In test.txt:</p>

<pre><code>rt : objective
tr350rt : objective
rtrt : objective
@username : objective
@user_1236 : objective
@254test!! : objective
@test : objective
#15 : objective
</code></pre>

<p>My codes:</p>

<pre><code>import re
file3 = 'C://Users/Desktop/test.txt'
rfile3 = open(file3).read()
for altext in rfile3.split("\n"):
    saltext = altext.split("\t")
    for saltword in saltext:
        ssaltword = saltword.split(" ")
        if re.search(r'^rt$', ssaltword[0]):
        print ssaltword[0], ssaltword[2]
        testreplace = open(file3, 'w').write(rfile3.replace(ssaltword[0], ""))
        if re.search(r'^@\w', ssaltword[0]):
            print ssaltword[0], ssaltword[2]
        testreplace = open(file3, 'w').write(rfile3.replace(ssaltword[0], ""))
</code></pre>

<p>I got:</p>

<pre><code> : objective
tr350 : objective
 : objective
@username : objective
@user_1236 : objective
@254test!! : objective
 : objective
#15 : objective
</code></pre>

<p>I am trying to replace only "rt" and all @ with space</p>

<p>But from my codes all "rt" were replaced and only one @ was replaced.</p>

<p>I would like to get:</p>

<pre><code> : objective
tr350rt : objective
rtrt : objective
 : objective
 : objective
 : objective
 : objective
#15 : objective
</code></pre>

<p>Any suggestion?</p>
