Skip to content

Instantly share code, notes, and snippets.

@jacob414
Created March 1, 2012 11:15
Show Gist options
  • Save jacob414/1949138 to your computer and use it in GitHub Desktop.
Save jacob414/1949138 to your computer and use it in GitHub Desktop.
Simple demo of Altered States context manager
from altered import state
class A(object): pass
o = A()
o.foo = 'foo'
with(state(o, foo='bar')):
# prints 'bar'
print o.foo
# prints 'foo', o.foo now restored to previous value
print o.foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment