3 ms·
Thanks. The constructor thing can be illustrated similarly (found an online compiler, I don't normally python...). class A: i = -1 def __in
by alkonaut 9y ago
Thanks. The constructor thing can be illustrated similarly (found an online compiler, I don't normally python...).
class A:
i = -1
def __init__(self, num):
if num <= 0:
raise(Exception('noo!'))
def go(self):
print('A has value {}'.format(self.i))
class B:
def go(self):
print ("B ran!")
b = B()
b.go()
b.__class__ = A
b.go()