Invisible function attributes
newsgroups at jhrothjr.com
Thu Sep 4 17:49:33 CEST 2003
"Olivier Lefevre" <lefevrol at yahoo.com> wrote in message
news:51809ae4.0309040627.28d7a075 at posting.google.com...
> Thanks to all those who replied.
> > ...what I'm guessing you haven't figured out yet is that everything
> > works like this in Python.
> Very possibly. I am coming to python from Java and I want to investigate
> the weird stuff precisely because either it's a one-off (in which case
> I'll make a note to myself to ignore it and not use it) or it holds the
> key to what is specific about the language. I seem to have hit pay dirt
> with this one ;-)
> Nudged by the dot syntax, I was thinking of this function attribute as
> if it were a sort of class member (i.e., pretending for a while this
> function is a class) and, since functions can't have instances, treating
> it as a sort of static member of the function, which should be available
> as soon as declared. Obviously I got it all wrong. Instead, they work
> like local variables except that they "persist" after the function has
> exited. That still feels weird to me. What are they used for? Give me
> a compelling reason to have such a beast in the language.
I don't know of a really compelling reason, other than it simply
works that way. Like everything else in the language, functions
are objects, which means that they have a dictionary at their
core. Therefore, functions can have attributes.
The only use I can think of would be definitely advanced
programming. Functions are first class objects, which means
they can be rebound anywhere you want them. If you find
a good reason to do that, then as an extension you might find
a reason to add attributes to classify what you've got so you
can manage the process.
As I said, I'm reaching with this one...
> OTOH, does this behaviour have anything to do with so-called "futures"?
No. Future is a feature so that experimental features can be added to the
language in one release, and then made standard in a future release.
> -- O.L.
More information about the Python-list