decorators question
king kikapu
aboudouvas at panafonet.gr
Mon Dec 4 17:03:04 EST 2006
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. It must have a body (a
call to a(some) method(s)) so it can execute something, right ??
In Soni's example (Soni thanks for the code), it indeed prints "called
foo" but if i remove the @foo statement,
as i see right now in the debugger, it does not execute anything.
I recap: if i put only functions declarations on a .py file, like
these:
def A(): print "a"
def B(): print "b"
def C(): print "c"
and run the program, nothing happens, nothing executed. I have to put a
statment like print A() or b() to cause code execution.
But if i simple declare a decorator for one function, like the one that
Soni gave me, then it caused the deco function to execute. Why is that
??
On Dec 4, 9:46 pm, Soni Bergraj <soniberg... at youjoy.org> wrote:
> There was a copy-and-paste error with my last message. Better try this
> for foobar.py:
>
> def foo(f):
> print "called foo"
> return 'some text'
> @foo
> def bar():
> print "called bar"
>
> --
> Soni Bergrajhttp://www.YouJoy.org/
More information about the Python-list
mailing list