Printing __doc__

Cameron Laird claird at lairds.us
Wed Mar 21 18:28:31 EDT 2007


In article <1174510376.417966.110370 at e1g2000hsg.googlegroups.com>,
gtb <goodTweetieBird at hotmail.com> wrote:
>On Mar 21, 3:35 pm, Peter Otten <__pete... at web.de> wrote:
			.
			.
			.
>> >>> import sys
>> >>> def docstring():
>>
>> ...     return sys._getframe(1).f_code.co_consts[0]
>> ...>>> def foo():
>>
>> ...     print "My docstring is %r" % docstring()
>> ...>>> def bar():
>>
>> ...     "bar's docstring"
>> ...     print "My docstring is %r" % docstring()
>> ...>>> foo()
>>
>> My docstring is None>>> bar()
>>
>> My docstring is "bar's docstring"
>>
>> No idea how brittle that might be, though.
>>
>> Peter
>
>Thanks.
>
>Pardon my ignorance, but brittle?
>

Peter is trying to communicate that some aspects of Python are
quite conservative, well-documented, and unlikely to change
across versions or implementations.  The syntax of, let's say,
"def", is an example of such an aspect.

Peter has no particular evidence about the guarantees of the
    sys._getframe(1).f_code.co_consts[0]
resolution; for all he or I know, the core Python maintainers
might change in an upcoming release the implementation of 
co_consts.  That's what I believe he intends you understand by
"brittle".



More information about the Python-list mailing list