public
Last active — forked from mashiro/env.py

  • Download Gist
env.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!/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()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.