Advertisement
Albartash

Jokes

Feb 10th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. # Some jokes on Python :)
  2.  
  3. class A():
  4.     def foo(self):
  5.         print 'foo'
  6.     def bar(self):
  7.         print 'bar'
  8.  
  9. class B():
  10.     def __init__(self, param = -1):
  11.         self.x = param
  12.  
  13. # Now have a nice day...
  14.  
  15. a1 = A()
  16. a2 = A()
  17.  
  18. a1.foo(), a2.foo()
  19.  
  20. A.bar = lambda: 1       # function that returns 1 - replaced for class A. Will not touch a1 and a2!
  21.  
  22. a3 = A()
  23.  
  24. # Please enjoy yourselves...
  25. print dir(a1)
  26. print dir(a2)
  27. print dir(a3)
  28. print dir(A)
  29.  
  30. ############################################################
  31. b1 = B(1)
  32.  
  33. # ...
  34. del B.__init__      # Remove constructor from class
  35.  
  36. print dir(b1)
  37. print dir(B)
  38.  
  39. # Now try to create object :)
  40.  
  41. try:
  42.     b2 = B(2)
  43. except:
  44.     print ':('
  45.  
  46. b3 = B()                # Though the default constructor is possible way to...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement