
Hi People
I have some difficulty with classes in Python.
I want to call a method, belonging to class A, from class B. I looked at online examples and tested them successfully, but my code generates an error which I do not understand. I will attach the .py file for details, but in essence here is what I'm trying to do:
I have some difficulty with classes in Python.
I want to call a method, belonging to class A, from class B. I looked at online examples and tested them successfully, but my code generates an error which I do not understand. I will attach the .py file for details, but in essence here is what I'm trying to do:
class A: def __init__(self,a,b): self.a_ = a self.b_ = b def set_a(self,aa): self.a_ = aa class B: def __init__(self,c): self.c_ = c def set_a_of_classA(self,x): A.set_a(self,x) def main(): a = A(1,2) b = B(7) b.set_a_of_classA(10)The code raises this error:
Error:AttributeError: 'b' object has no attribute 'a_'
Attached Files