@contextmanager
def filetexts(d, open=open, mode='t', use_tmpdir=True):
 with (tmp_cwd() if use_tmpdir else noop_context()):
  for (filename, text) in d.items():
   f = open(filename, ('w' + mode))
   try:
    f.write(text)
   finally:
    try:
     f.close()
    except AttributeError:
     pass
  (yield list(d))
  for filename in d:
   if os.path.exists(filename):
    with ignoring(OSError):
     os.remove(filename)

@ contextmanager def filetexts ( d , open = open , mode = 't' , use_tmpdir = True ) : with ( tmp_cwd ( ) if use_tmpdir else noop_context ( ) ) : for ( filename , text ) in d . items ( ) : f = open ( filename , ( 'w' + mode ) ) try : f . write ( text ) finally : try : f . close ( ) except AttributeError : pass ( yield list ( d ) ) for filename in d : if os . path . exists ( filename ) : with ignoring ( OSError ) : os . remove ( filename )
dumps a number of textfiles to disk d - dict a mapping from filename to text like {a .