dimkor
dimkor

Reputation: 71

How to create a new function parameter dynamically

I have a chat bot, that shows every function parameter, so the user can change it and then get the function result in chat.

Let's say I have a function:

def func(a=0, b=0):
    return a+b

func(*user_settings)

But I want it to be able to recognize the user. I can't just add a 'user' parameter because it will be shown in chat. Can I add a parameter to the function dynamically, so it becomes smth like:

def func(a=0, b=0):
    print(func.user)
    return a+b

(add 'user' parameter)
func(*user_settings)

Function is an object, right? I think that just hardcode not to show a specific parameter is too dumb. p.s. the function is also decorated.

Upvotes: 0

Views: 103

Answers (1)

dimkor
dimkor

Reputation: 71

func.user=user

works for me, thanks for @ThomasLang

Upvotes: 1

Related Questions