parameters: (targetfile, sourcefile, dict)
docstring: Replace all instances of the keys of dict with their values.
      For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
      then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
docstring_summary: Replace all instances of the keys of dict with their values.
      For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
      then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
docstring_tokens: Replace all instances of the keys of dict with their values . For example if dict is { %VERSION% : 1 . 2345 %BASE% : MyProg } then all instances of %VERSION% in the file will be replaced with 1 . 2345 etc .
function: def do_subst_in_file(targetfile, sourcefile, dict):
      """Replace all instances of the keys of dict with their values.
      For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
      then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
      """
      try:
          f = open(sourcefile, 'rb')
          contents = f.read()
          f.close()
      except:
          print "Can't read source file %s"%sourcefile
          raise
      for (k,v) in dict.items():
          v = v.replace('\\','\\\\') 
          contents = re.sub(k, v, contents)
      try:
          f = open(targetfile, 'wb')
          f.write(contents)
          f.close()
      except:
          print "Can't write target file %s"%targetfile
          raise
function_tokens: def do_subst_in_file ( targetfile , sourcefile , dict ) : try : f = open ( sourcefile , 'rb' ) contents = f . read ( ) f . close ( ) except : print "Can't read source file %s" % sourcefile raise for ( k , v ) in dict . items ( ) : v = v . replace ( '\\' , '\\\\' ) contents = re . sub ( k , v , contents ) try : f = open ( targetfile , 'wb' ) f . write ( contents ) f . close ( ) except : print "Can't write target file %s" % targetfile raise