1

Is it possible (and if so, how) to change the parameters of a function after definition?

Example:

from inspect import signature
def f(a, b, c):
    print(a + b + c)

for i in signature(f).parameters:
    print(i)

changeparameters(f, "d", "e")
print()

for i in signature(f).parameters:
    print(i)

Would output:

a
b
c

d
e
4
  • Just curious. What are you trying to achieve? Commented Sep 4, 2013 at 19:15
  • Also curious: how do you want to call the function after it has been changed from taking 3 parameters to 2? Commented Sep 4, 2013 at 19:17
  • I have realised I was going about a problem in completely the wrong way, and so I will close this question as I do not think it is helpful (I'm fairly sure it isn't possible, and for good reason, it doesn't make sense). Commented Oct 5, 2013 at 16:10
  • This question appears to be off-topic because it is unanswerable. Commented Oct 5, 2013 at 16:11

1 Answer 1

2

Just re def the function name with the new parameters - since the will not be used by the original you would need to anyway.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.