function attributes are like function objects
Fredrik Lundh
fredrik at effbot.org
Fri Feb 2 04:30:32 EST 2001
Tim Peters wrote:
> [/F]
> > well, if people are too lazy to write
> >
> > def f(...):
> > ...
> > a[f] = "something"
> >
> > do you really think they'll find it much easier to write:
> >
> > def f(...):
> > ...
> > f.a = "something"
>
> Believe it or not, I do. Bets? Don't forget methods when deciding how easy
> the first alternative is, and that decorating methods (not top-level
> functions) is the primary cause of docstring abuse.
Works for methods too:
class Spam:
a = {}
def f(...):
...
a[f] = "something"
You can dig it out with a one-liner (or 2-3 lines, if you want a
more general version -- put it in the "code" module, where it
belongs...)
> > -- face it, "because we can" isn't a very good argument
> > when deciding what to add to the language core...)
>
> Hmm. I suppose the PEP would be that much stronger had Barry thought to
> mention this argument <ahem>:
>
> http://python.sourceforge.net/peps/pep-0232.html
Sure looks like "because we can" to me...
Or maybe "because it's more fun to hack the core than to hack
the library". (For some reason, the python-devers seem to prefer
writing C/Java over Python...)
On the other hand, this isn't such a big deal, especially not com-
pared to some of the stuff I've seen on python-dev lately. I'm
pretty sure a third-party python implementer can ignore function
attributes, and nobody will ever notice...
Cheers /F
More information about the Python-list
mailing list