Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Example:
- class_variable = 'Hello'
- @staticmethod
- def a():
- return 'A'
- def b():
- return 'B'
- @classmethod
- def c(cls):
- cls.a()
- cls.b()
- #cls.d() # ERROR: method need instance
- return 'C', cls, cls.class_variable
- def d(self):
- self.a()
- #self.b() # ERROR: method doesn't need instance
- self.c()
- return 'D', self, self.class_variable
- e = Example()
- print('Example.a:', Example.a)
- print('Example.b:', Example.b)
- print('Example.c:', Example.c)
- print('Example.d:', Example.d)
- print('-------')
- print('Example.a():', Example.a())
- print('Example.b():', Example.b())
- print('Example.c():', Example.c())
- try:
- print('Example.d():', Example.d())
- except Exception as ex:
- print('Example.d():')
- print(' ERROR:', ex)
- print(" ERROR: method need instance")
- #print(Example.d(Example))
- print('-------')
- print('e.a:', e.a)
- print('e.b:', e.b)
- print('e.c:', e.c)
- print('e.d:', e.d)
- print('-------')
- print('e.a():', e.a())
- try:
- print('e.b():', e.b())
- except Exception as ex:
- print('e.b():')
- print(' ERROR:', ex)
- print(" ERROR: method doesn't need instance")
- print('e.c():', e.c())
- print('e.d():', e.d())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement