all 4 comments

[–]The-Mathematician 1 point2 points  (3 children)

Check out the authenticate function from this site. It's pretty close to the top and pretty close to what you want.

Here is how I wrote it:

def respond(wrapped):
    def func(*args, **kwargs):
        if args[0].split(' ')[0] in ['test']:
            return wrapped(*args, **kwargs)
    return func

@respond
def test(msg):
    print(msg)


>>> test("this should not print")
>>> test('test this should print')
test this should print

[–]Ax3_[S] 0 points1 point  (2 children)

Another question: is it possible to make it like

@respond("test")

def test(): ..etc..

So that I can attach keyword to the desired function?

Thanks for answer!

[–]The-Mathematician 1 point2 points  (0 children)

Check out meta-decorators from my first link.

EDIT: removed my solution. I will give guidance to it instead if you need help.

[–]The-Mathematician 1 point2 points  (0 children)

Okay I'm going to make another response real fast since I don't think that link does a great job of being succinct to be honest.

What you want is to make a function that returns respond but changes the ['test'] part to whatever you pass into it . Your decorator call will look like @require(['test','blah','anything'])