Created
October 16, 2010 05:04
-
-
Save mashiro/629448 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import inspect | |
def ulocals(n): | |
frame = inspect.stack()[n][0] | |
return frame.f_locals | |
def uglobals(n): | |
frame = inspect.stack()[n][0] | |
return frame.f_globals | |
class Foo(object): | |
def __init__(self, locals=None, globals=None): | |
self.locals = locals or ulocals(2) | |
self.globals = globals or uglobals(2) | |
def __call__(self): | |
print self.locals | |
#print self.globals | |
def main(): | |
value = 'local variable' | |
f = Foo() | |
f() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment