title: Python script to replace #define values in C file
body: <p>I am really really new to Python and I am trying to built a script to change the values of #define variables.
  My code seems to work however it ruins the C indentation of the output file.
  So how can I workaround the white space problem?
  Any suggestion for smarter implementation than mine will be highly appreciated!</p>
  
  <pre><code>KEYWORDS=["PERIOD","PWM_RATE","DUTY_OFFSET","MAX_DUTY"]
  VALS=[3,3,3,3]    
  import re
  f1 = open('../src/in.c','r')
  f2 = open('../src/out.xc','w')
  for line in f1:
      s=line.split()
      if len(s)&gt; 1 and s[1] in KEYWORDS:
          s[2] = VALS[1]
      f2.write(' '.join(s)+'\n')
  f1.close()
  f2.close()
  </code></pre>