Are decorators really that different from metaclasses...

Paul Morrow pm_mon at yahoo.com
Thu Aug 26 15:31:55 CEST 2004


Arthur wrote:

> On Thu, 26 Aug 2004 21:05:46 +1000, Anthony Baxter
> <anthonybaxter at gmail.com> wrote:
> 
>>def foo():
>>   __name__ = '%s_banana'%(__name__) 
>>
> 
> 
> 
> I'm not sure what you are driving at here, but ...
> 
> Aa a practical matter, wouldn't it be nice to be able to use string
> substitution on a docstring placed in its usual location under def
> foo().
> 
> That I need to place my __doc__ under the function can't be considered
> a good thing, or intutive thing.
> 
> Sort of like having to do transformations after and under the function
> ;)
> 
> Art

Currently, you can change a doc string outside of a function, by 
modifying the function's __doc__ attribute

   >>> def foo():
   ...     """ I am foo """
   ...
   >>> foo.__doc__
   ' I am foo '
   >>> foo.__doc__ = foo.__doc__ + 'indeed'
   >>> foo.__doc__
   ' I am foo indeed'
   >>>

IMO, to change it inside of a function def should be (but isn't) as easy 
as...

   >>> def foo():
   ...     """ I am foo """
   ...     __doc__ = __doc__ + 'indeed'

Paul






More information about the Python-list mailing list