Wednesday, January 10, 2018

python class inherit from parent class that super(SelfClassType, self) __init__ or __class__

#The first is used to initialise newly created object, and receives arguments used to do that:
class Input(object):
def __init__(self, x, y):
self.x = x
self.y = y
print("Input inited x=%d, y=%d" % (self.x, self.y))

def __call__(self, a):
self.x = self.x + a
print(self.x, self.y)


class AInput(Input):
input_type = 'password'

def __init__(self, hide_value=True):
self.hide_value = hide_value
super(AInput, self).__init__(5, 10)
print("AInput inited")

def __call__(self, field):
return super(AInput, self).__call__(field)


a = AInput()# __init__

#The second implements function call operator.
a(2)# __call__

No comments: