Class calling functions automatically in Python
This is my current class:
class abc:
def __init__(self, a=0, b=0):
self.c= c
self.b = b
self.a = a
def type_func(self):
type = raw_input("enter the type")
if type == "A":
self.b = 5
else:
self.b = 1
#cab().register()
def input(self):
self.c = int(raw_input("enter c"))
#cab().display()
def display(self):
print self.a,self.b*self.c
c = cab()
I want to call c.type_func()
, and then make the program automatically calls input()
, and when this is done call display()
.
How should I do it?
+3
WhiteFlameAB
source
to share
1 answer
You can call the functions you want by simply adding self.
Thus, to invoke input, you must invoke self.input()
or to display the invocation self.display()
. The function will use the already created object. Call this within the desired class method.
+2
gwhiz
source
to share