Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. >>> class A(object):
  2.     def __init__(self):
  3.         print "The self.__class__ attribute is:", self.__class__
  4.     def getClassAddress(self):
  5.         RETURN self.__class__
  6.  
  7.    
  8. >>> a = A()
  9. The self.__class__ attribute IS: <class '__main__.A'>
  10.  
  11. >>> A().getClassAddress() == A # we test IF the self.__class__ IS equal TO the A IN the global scope; i.e the actual class name
  12. The self.__class__ attribute IS: <class '__main__.A'>
  13. TRUE
  14.  
  15. >>> A().getClassAddress() IS A # This TIME we ensure that they are the same object, AND NOT a copy; i.e same memory address
  16. The self.__class__ attribute IS: <class '__main__.A'>
  17. TRUE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement