Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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