Last active
April 20, 2016 16:12
-
-
Save Atala/cf32d591aebef387b16945cbfa78e698 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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