I have written a class called cl
:
class cl :
def __int__(self):
self.a = 0
def increment(self):
self.a +=1
def print_a(self):
print ("value : "+str(self.a))
I have written another class called test
. However, I got an error when calling methods.
from cl import *
class test :
def __int__(self):
self.b = 0
self.c = cl()
def main(self):
self.c.increment()
self.c.print_a()
self.c.increment()
self.c.print_a()
d = test()
d.main()
What I got is this:
Traceback (most recent call last):
File "test_file.py", line 19, in <module>
d.main()
File "test_file.py", line 12, in main
self.c.increment()
AttributeError: test instance has no attribute 'c'
Can anyone explain why that happens and what is the issue with my code? I am a high school student. Can you explain to me? And can you help me to fix this?