title: how to replace a value under specific word in python?
body: <p>I have this code to interpolate between the values and return Z value for specific X and Y. I am trying to open another file (<code>world.txt</code>) and paste the value under specific name <code>Nz</code>.</p>
  
  <p>The way the file is organised is </p>
  
  <pre><code>Nx
  5
  Ny
  0.1
  Nz
  0.8
  </code></pre>
  
  <p>But what i am getting is <code>givemeZ(0.5,0.04)</code> instead of the value <code>0.78</code></p>
  
  <p>Would you please suggest some ideas of how to fix it?</p>
  
  <pre><code>import numpy as np
  from scipy import interpolate
  from scipy.interpolate import griddata
  import itertools
  from scipy.optimize import curve_fit
  
  xx= 0.15, 0.3, 0.45, 0.5, 0.55
  yy= 0.01, 0.02, 0.03, 0.04, 0.05
  zz= 0.75, 0.76, 0.77, 0.78, 0.79
  
  tck = interpolate.bisplrep(xx, yy, zz, s=0)    
  def givemeZ(X,Y):
      return interpolate.bisplev(X,Y,tck)
  ## to replace the value 
  with open('world.txt', 'r') as file :
    filedata = file.read()
  # Replace the target string
  filedata = filedata.replace('Nz', 'givemeZ(0.5,0.01)')
  # Write the file out again
  with open('world.txt', 'w') as file:
    file.write(filedata)
  </code></pre>