Guest User

Untitled

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