code: def _filter_file(src, dest, subst):
      
      substre = re.compile(r'\$(%s)' % '|'.join(subst.keys()))
      def repl(m):
          return subst[m.group(1)]
      with open(src, "rt") as sf, open(dest, "wt") as df:
          while True:
              l = sf.readline()
              if not l:
                  break
              df.write(re.sub(substre, repl, l))
docs: Copy src to dest doing substitutions on the fly.