Created
September 9, 2014 14:54
-
-
Save robdmc/44c4c50deef1e3f91e03 to your computer and use it in GitHub Desktop.
A python decorator to use a class as a context manager that yields an instance
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
def contextify(cls): | |
@contextmanager | |
def wrapper(*args, **kwargs): | |
yield cls(*args, **kwargs) | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment