Guest User

Untitled

a guest
Oct 20th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. ## Broken in Python 3.1.2
  2.  
  3. # Python 2.6: prints 'it is working'
  4. # Python 3.1.2: "NameError: global name 'a_func' is not defined"
  5. class Testing(object):
  6. def __init__(self):
  7. exec("""def a_func():
  8. print('it is working')""")
  9. a_func()
  10.  
  11. Testing()
  12.  
  13. ## Works in both 2.6 and 3.1.2
  14.  
  15. # Python 2.6: prints 'it is working'
  16. # Python 3.1.2: prints 'it is working'
  17. class Testing(object):
  18. def __init__(self):
  19. def a_func():
  20. print('it is working')
  21. a_func()
  22.  
  23. Testing()
Add Comment
Please, Sign In to add comment