Created
March 17, 2010 07:34
-
-
Save kekssw/335000 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
from contextlib import contextmanager | |
@contextmanager | |
def mark_enabling(value): | |
global mark | |
try: | |
mark = True | |
yield value | |
finally: | |
mark = False | |
def test(): | |
global mark | |
print 'Yes' if mark else 'No' | |
test() | |
# No | |
with mark_enabling('Salsa') as v: | |
test() | |
print 'Value:', v | |
# Yes | |
# Value: Salsa | |
test() | |
# No |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment