title: Python: replace a string by a float in txt file
body: <p>Here is a problem. </p>
  
  <p>I have a .py file and a .txt.
  To simplify, my .txt looks like:</p>
  
  <pre><code>@x@
  </code></pre>
  
  <p>In the .py I have </p>
  
  <pre><code>x=15
  </code></pre>
  
  <p>I would like to replace @x@ in the txt by the value saved in the py, ie my txt should look like</p>
  
  <pre><code>15
  </code></pre>
  
  <p>I tried with this:</p>
  
  <pre><code>for i, line in enumerate(fileinput.input('mytxtfile.txt', inplace = 1)):
      sys.stdout.write(line.replace('@x@', 'x'))
  </code></pre>
  
  <p>or with</p>
  
  <pre><code>for i, line in enumerate(fileinput.input('mytxtfile.txt', inplace = 1)):
      sys.stdout.write(line.replace('@x@', 'str(x)'))
  </code></pre>
  
  <p>The problem is that the "replace" method seems to consider only strings and I need to evaluate the value of the string.
  Any idea how to do it?</p>
  
  <p>Thanks </p>