You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
573 B

# Calling an inherited classmethod
class Base:
@classmethod
def foo(cls):
print(cls.__name__)
try:
Base.__name__
except AttributeError:
print("SKIP")
raise SystemExit
class Sub(Base):
pass
Sub.foo()
# overriding a member and accessing it via a classmethod
class A(object):
foo = 0
@classmethod
def bar(cls):
print(cls.foo)
def baz(self):
print(self.foo)
class B(A):
foo = 1
B.bar() # class calling classmethod
B().bar() # instance calling classmethod
B().baz() # instance calling normal method