def apply_to_text_file(f):
 @wraps(f)
 def f_in_file(fname):
  with io.open(fname, 'r', encoding='utf-8') as inf:
   data = inf.read()
  data = f(data)
  with io.open(fname, 'w+', encoding='utf-8') as outf:
   outf.write(data)
 return f_in_file

def apply_to_text_file ( f ) : @ wraps ( f ) def f_in_file ( fname ) : with io . open ( fname , 'r' , encoding = 'utf-8' ) as inf : data = inf . read ( ) data = f ( data ) with io . open ( fname , 'w+' , encoding = 'utf-8' ) as outf : outf . write ( data ) return f_in_file
apply a filter to a text file .