[Tutor] global variables/constants versus volatile variables/constants

Steven D'Aprano steve at pearwood.info
Sat Jun 14 03:42:24 CEST 2014


Albert-Jan, I've been meaning to ask for a long time... I don't suppose 
you're hitting "Forward" rather than "Reply" in your posts are you? 
Because I've never seen replies from anyone else use the same style as 
your replies.

Further comments below.

On Fri, Jun 13, 2014 at 10:14:46AM -0700, Albert-Jan Roskam wrote:

> Hmm, if I create the namedtuple with 'verbose=True' it *really* makes clear why it took so much longer.
> (what's '_property' btw? I know 'property' and the newer decorator wih the same name, but not _property).

_property is just property renamed. If you read the source code to 
namedtuple, you will see something like the line:

    _property = property

or possibly:

    from builtins import property as _property

That's likely done to make it a local variable, and so a little faster 
(although I don't know why the author bothered, it will make so little 
difference), or possibly to prevent clashes in case the caller defines a 
field name called "property". I'm not sure, but they are my guesses.


[...]
>     v000 = _property(_itemgetter(0), doc='Alias for field number 0')
> 
>     v001 = _property(_itemgetter(1), doc='Alias for field number 1')
> 
>     v002 = _property(_itemgetter(2), doc='Alias for field number 2')

[snip 97 more lines]

Yes, thank you, we get the picture. No need to show 100 examples.



-- 
Steven


More information about the Tutor mailing list