decorators question
Fredrik Lundh
fredrik at pythonware.com
Mon Dec 4 17:27:51 EST 2006
king kikapu wrote:
> At first, i am coming from another (language) programming world (C#
> mainly) and i hope you understand my wonders.
>
> Ok then, you tell me that the interpreter always execute the code in a
> module...If there are only def declarations in the module and no code
> to invoke them it does not execute anything.
you're not listening. "def" is not a declaration, it's an executable
statement, just like "print" and ordinary assignments and "import" and
"class" and all the others.
the "def" statement itself is *executed* to define the function; it
takes the argument specification and the function code body, and creates
a new function object. the resulting object is assigned to an ordinary
variable.
the only thing that differs if you add a decorator to the mix is that
the function object is passed to the decorator function *before* it's
assigned to a variable.
</F>
More information about the Python-list
mailing list