0

I'm having trouble appending to an existing function.

def functionA(self):
 var1 = hi
 var2 = bye
Class A(object):
 def functionB(self)
 var1 = hi <-- insert functionA here
 var2 = bye
 var3 = "something not in functionA"

Sorry I know this is probably basic, but I can't find this anywhere. The closest I've found is here Python add to a function dynamically . Thanks in advance for your help!

asked Oct 21, 2013 at 0:48
4
  • 1
    Thats probably as close as you are going to get. You'd usually do that with inheritance, which is not really append. Commented Oct 21, 2013 at 0:53
  • 1
    XY problem - what are you trying to ultimately accomplish that can't be done by just calling functionA() from functionB()? Commented Oct 21, 2013 at 0:54
  • @millimoose I'm just trying to simplify my code. I want all the variables from functionA in functionB. Commented Oct 21, 2013 at 0:56
  • Hm, I misassumed you were trying to do something needlessly advanced. Whoops. Commented Oct 21, 2013 at 1:01

1 Answer 1

3
def functionA():
 var1 = hi
 var2 = bye
 return (var1, var2)
class A(object):
 def functionB(self):
 var1, var2 = functionA()
 var3 = "something not in functionA"

how about that?

answered Oct 21, 2013 at 0:51
Sign up to request clarification or add additional context in comments.

1 Comment

thanks! I wasn't expecting an answer like this, but it works for my application!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.