@contextmanager<EOL>def atomic_write(filename):
f = _tempfile(os.fsencode(filename))<EOL>try:<EOL><INDENT>yield f<EOL><DEDENT>finally:<EOL><INDENT>f.close()<EOL>os.replace(f.name, filename)<EOL><DEDENT>
Open a NamedTemoraryFile handle in a context manager