Changing contents of a file - Python
<p>So I have a program which runs. This is part of the code:</p>

<pre><code>FileName = 'Numberdata.dat'
NumberFile = open(FileName, 'r')
for Line in NumberFile:
  if Line == '4':
    print('1')
  else:
    print('9')
NumberFile.close()
</code></pre>

<p>A pretty pointless thing to do, yes, but I'm just doing it to enhance my understanding. However, this code doesn't work. The file remains as it is and the 4's are not replaced by 1's and everything else isn't replaced by 9's, they merely stay the same. Where am I going wrong?</p>

<p>Numberdata.dat is <code>"444666444666444888111000444"</code></p>

<p>It is now:</p>

<pre><code>FileName = 'Binarydata.dat'
BinaryFile = open(FileName, 'w')
for character in BinaryFile:
  if charcter == '0':
    NumberFile.write('')
  else:
    NumberFile.write('@')
BinaryFile.close()
</code></pre>
