Python Forum
How can I sum up the values of two functions?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I sum up the values of two functions?
#1
Hi,

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
 
Reply
#2
print(A.some(a,b,c)) - will give you it is a function, with an address. Your code is actually trying to reassign the function to a different address, twice as high. Oops!.

You also have classes but have not instantiated either one.

Recognize that variables in class B do not automagically see those in class A.
Advice - I always use variable names inside classes and functions that are different from those outside. That way I never worry about confusing scope and which A.a is which.
Look at this:
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.a = 2*A.a
        A.b = 2*A.b
        A.c = 2*A.c
        
                 
    def lion(self):
             
        A.p= A.p * 3
        A.g = A.g *3
        A.f = A.f *3

letter_a = A
Reply
#3
Jap, it works! thanks!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  partial functions before knowing the values mikisDeWitte 4 537 Dec-24-2023, 10:00 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020