@contextmanager
def alt_file(current_file):
 _alt_file = (current_file + '-alt')
 (yield _alt_file)
 try:
  shutil.move(_alt_file, current_file)
 except IOError:
  pass

@ contextmanager def alt_file ( current_file ) : _alt_file = ( current_file + '-alt' ) ( yield _alt_file ) try : shutil . move ( _alt_file , current_file ) except IOError : pass
create an alternate file next to an existing file .