@contextmanager
def mutated_working_copy(files_to_mutate, to_append=u'\n '):
 assert to_append, u'to_append may not be empty'
 for f in files_to_mutate:
  with open(f, u'ab') as fh:
   fh.write(to_append)
 try:
  (yield)
 finally:
  seek_point = (len(to_append) * (-1))
  for f in files_to_mutate:
   with open(f, u'ab') as fh:
    fh.seek(seek_point, os.SEEK_END)
    fh.truncate()

@ contextmanager def mutated_working_copy ( files_to_mutate , to_append = u'\n ' ) : assert to_append , u'to_append may not be empty' for f in files_to_mutate : with open ( f , u'ab' ) as fh : fh . write ( to_append ) try : ( yield ) finally : seek_point = ( len ( to_append ) * ( - 1 ) ) for f in files_to_mutate : with open ( f , u'ab' ) as fh : fh . seek ( seek_point , os . SEEK_END ) fh . truncate ( )
given a list of files .