Skip to content

Instantly share code, notes, and snippets.

@Atala
Last active April 20, 2016 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Atala/cf32d591aebef387b16945cbfa78e698 to your computer and use it in GitHub Desktop.
Save Atala/cf32d591aebef387b16945cbfa78e698 to your computer and use it in GitHub Desktop.
import os
class RemoveFileContextManager(object):
def __init__(self, filename):
self.filename = filename
def __enter__(self):
pass
def __exit__(self, *args):
if os.path.exists(self.filename):
os.remove(self.filename)
# usage
with RemoveFileContextManager(filename) as f:
do_things()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment