Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. a = 100
  2.  
  3. def foo(x):
  4. print "x is {}, a is {}".format(x,a)
  5. print "locals:" + '*' * 10
  6. print locals()
  7. print "globals:" + '*' * 10
  8. print globals()
  9. print abs(1)
  10.  
  11. def main():
  12.  
  13. source = 'foo(x)'
  14. l = {'foo':foo, 'x':1}
  15. exec(source,{'__builtins__': None}, l)
  16.  
  17. if __name__ == '__main__':
  18. main()
  19.  
  20. x is 1, a is 100
  21. locals:**********
  22. {'x': 1}
  23. globals:**********
  24. {'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}
  25. 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement