
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:
The code raises this error:
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
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 ) |
Error:AttributeError: 'b' object has no attribute 'a_'
Attached Files