Reading a textfile into a String
<p>I'm just starting to learn python and have a  textfile that looks like this:</p>

<pre><code>Hello

World


Hello
World
</code></pre>

<p>And I want to add the numbers '55' to the beggining and end of every string that starts with 'hello'</p>

<p>The numbers '66' to the beggining and every of every string that starts with 'World'</p>

<p>etc</p>

<p>So my final file should look like this:</p>

<pre><code>55Hello55

66World66


55Hello55
66World66
</code></pre>

<p>I'm reading the file in all at once, storing it in a string, and then trying to append accordingly</p>

<pre><code>fp = open("test.txt","r")
strHolder = fp.read()
print(strHolder)

if 'Hello' in strHolder:
    strHolder = '55' + strHolder + '55'
if 'World' in strHolder:
    strHolder = '66' + strHolder + '66'
print(strHolder)
fp.close()
</code></pre>

<p>However, my string values '55' and '66' are always being added to the front of the file and end of the file, not the front of a certain string and to the end of the string, where I get this output of the string:</p>

<pre><code>6655Hello

World


Hello
World
5566
</code></pre>

<p>Any help would be much appreciated.</p>

<p>once you have read the file:</p>

<pre><code>read_file = read_file.replace('hello','55hello55')
</code></pre>

<p>It'll replace all hellos with 55hello55</p>

<p>and use <code>with open(text.txt, 'r' ) as file_hndler:</code></p>

python