Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a = 100
- def foo(x):
- print "x is {}, a is {}".format(x,a)
- print "locals:" + '*' * 10
- print locals()
- print "globals:" + '*' * 10
- print globals()
- print abs(1)
- def main():
- source = 'foo(x)'
- l = {'foo':foo, 'x':1}
- exec(source,{'__builtins__': None}, l)
- if __name__ == '__main__':
- main()
- x is 1, a is 100
- locals:**********
- {'x': 1}
- globals:**********
- {'a': 100, 'main': <function main at 0x7f68c1d37c80>, '__builtins__': <module '__builtin__' (built-in)>, '__file__': 'play/eval_test.py', '__package__': None, '__name__': '__main__', 'foo': <function foo at 0x7f68c1d37c08>, '__doc__': None}
- 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement