doc string substition and overloading __doc__
Fernando Perez
fperez528 at yahoo.com
Fri May 2 21:12:19 EDT 2003
Steven Taschuk wrote:
> Quoth Fernando Perez:
> [...]
>> Note that, in a quirk of counter-intuitiveness, the following code is
>> accepted but the assignment fails silently. This one I'd call a wart, at
>> least:
>>
>> In [5]: def def3():
>> ...: def3.__doc__ = 'hi'
>> ...:
>>
>> In [6]: pdoc def3
>> No documentation found for def3
>
> The assignment doesn't fail, silently or otherwise; it just isn't
> run until the function is called, like any statement in a function
> body.
>
> >>> def foo():
> ... foo.__doc__ = 'Bar!'
> ...
> >>> foo.__doc__
> >>> foo()
> >>> foo.__doc__
> 'Bar!'
Thunk. That was the sound of a slap on my own head :) Thanks, it is, of
course, obvious.
I should probably go for a beer instead of trying to code anymore.
Cheers,
f.
More information about the Python-list
mailing list