Reputation: 17
I have two classes. In class B I want to change the values of the variables in class A, which are defined in functions: some and anyt, with the help of the functions in class B: frog and lion. For example, I multiply by 2 or 3..
I get the Error:
File "E:/Python/Akustik/Akustik/Test.py", line 20
A.some(a,b,c) = A.some(a,b,c)* 2
^
SyntaxError: can't assign to function call
I know what does that mean, but i can't dispense with the functions in class A and B, does anybody have a tip?
here is the code:
class A:
def some(self,a, b, c):
self.a = 4
self.b = 2
self.c = 3
def anyt(self, p, g, f):
self.p = 5
self.g = 8
self.f = 1
class B(A):
def frog(self):
A.some(a,b,c) = A.some(a,b,c)* 2
def lion(self):
A.anyt(p,g,f)= A.anyt(p,g,f) * 3
Upvotes: 0
Views: 95
Reputation: 652
You cannot assign the value of an expression to a function call. In your case if you want to change the value of variables a, b, c, p, q, r. You will have to do something like this.
class A:
def __init__(self):
self.a = 1
self.b = 1
self.c = 1
self.p = 1
self.q = 1
self.r = 1
def some(self,a, b, c):
self.a = a
self.b = b
self.c = c
def anyt(self, p, g, f):
self.p = p
self.g = g
self.f = f
class B(A):
def frog(self):
self.some(self.a*2, self.b*2, self.c*2)
def lion(self):
self.anyt(self.p*3, self.g*3, self.f*3)
b = B()
b.frog()
print(b.c)
# Prints current value of c
This ensures the corresponding variable values change.
Upvotes: 3