Are decorators really that different from metaclasses...
jess.austin at gmail.com
Fri Aug 27 00:20:10 CEST 2004
Paul Morrow <pm_mon at yahoo.com> wrote in message news:<mailman.2423.1093527121.5135.python-list at python.org>...
> Currently, you can change a doc string outside of a function, by
> modifying the function's __doc__ attribute
> IMO, to change it inside of a function def should be (but isn't) as easy
> >>> def foo():
> ... """ I am foo """
> ... __doc__ = __doc__ + 'indeed'
I'm not trying to be mean, but why not use a class for this? This is
the whole point of "self" - provide a persistent, updateable namespace
for an object. (Note: explicit use of self in Python is a GOOD
THING!) An object that needs such a namespace should be a class. I'm
not sure why or how a function could use this anyway - why not just
set the docstring to " I am foo indeed" to start with? If what you're
looking for is a "configured function", which contains some data (or
metadata) that is set at the beginning of the function's lifecycle, to
me that would be a closure, which could be written like this:
""" I am foo """
foo.__doc__ += postfix
Or perhaps there is another application you had in mind, for which
this wouln't be sufficient? Paul: I admit I'm a bit confused by your
wanting a function to have access to its metadata, because I could
have sworn that earlier in the thread you defined metadata as data
about an object that that object would never use itself. I could be
thinking of someone else though...
More information about the Python-list