Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the Python function keyword do?

Tags:

python

I was looking at this line of code -

    result = function(self, *args, **kwargs)

And I was not able to find a definition of the function keyword for Python. Could someone link me to the docs and/or explain that this line of code does? I intuitively think I know, but I don't understand why I can't find any docs on it.

In searching through http://docs.python.org both the new module and its successor types seem to have something to do with it.

like image 542
Terrence Brannon Avatar asked Aug 23 '26 19:08

Terrence Brannon


2 Answers

That's because function is not a python keyword.

If you expand your view just a little, you can see that function is a variable (passed in as a parameter).

def autoAddScript(function):
    """
        Returns a decorator function that will automatically add it's result to the element's script container.
    """
    def autoAdd(self, *args, **kwargs):
        result = function(self, *args, **kwargs)
        if isinstance(result, ClientSide.Script):
            self(result)
            return result
        else:
            return ClientSide.Script(ClientSide.var(result))
    return autoAdd
like image 102
Darrick Herwehe Avatar answered Aug 26 '26 08:08

Darrick Herwehe


In this case function is just a formal parameter to the autoAddScript function. It is a local variable expected to have a type that allows you to call it like a function.

like image 22
Gabe Avatar answered Aug 26 '26 08:08

Gabe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!