Are decorators really that different from metaclasses...

Hallvard B Furuseth h.b.furuseth at usit.uio.no
Wed Sep 1 00:30:27 CEST 2004


Paul Morrow wrote:
>Paul Morrow wrote:
>> But why speculate.  Let's see if this is really going to be unclear in 
>> practice.  Ask someone who has never seen Python before which are the 
>> local variables in the following def.
>> 
>>    def circumference(diameter):
>>       """Calculate the diameter of a circle."""
>>       __author__ = 'Paul Morrow'
>>       __version__ = '0.1'
>>       pi = 3.14
>>       return pi * diameter
>
> And while you're at it, ask them which lines get executed at function 
> definition time, and which get executed when the function is called.

Of course that's obvious with your simple example, since it clearly
doesn't even use those variables and you can even tell from the function
name what the function ought to do.  What is not obvious is how it
works.

OK, I asked my neighbor: She suggested some kind of default variables.
She noticed that the variables were not being used; if the function had
been longer she would apparently have needed to read through the entire
function to be sure.

I think my guess would have been something like C's static variables.
The assigment would be initialization, but of a variable in the same
namespace.  Which seems similar to her guess, even though we thought
of it very differently.

-- 
Hallvard



More information about the Python-list mailing list