Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9176
| References | <20110710174121.GB12935@johnsons-web.com> <4E19E5A5.5020905@gmail.com> |
|---|---|
| Date | 2011-07-11 04:11 +1000 |
| Subject | Re: Function docstring as a local variable |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.844.1310321477.1164.python-list@python.org> (permalink) |
On Mon, Jul 11, 2011 at 3:47 AM, Andrew Berg <bahamutzero8825@gmail.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: RIPEMD160
>
> On 2011.07.10 12:41 PM, Tim Johnson wrote:
>> It possible for a function to print it's own docstring?
>>>> def test():
> ... """Hi there."""
> ... print(test.__doc__)
That's assuming that it knows its own name, and that that name hasn't
been rebound. Is there a way for a function to find its own self?
>>> def findself():
"""Find myself. Ooh look, there I am!"""
import sys
try:
1/0
except:
traceback=sys.exc_info()[2]
# Now I'm not sure what to do with traceback.
# traceback.tb_frame.f_code.co_name is the function name ("findself").
# Is there a way to get the function object?
I'm kinda half-way there, but I've never worked with traceback
objects. Someone will know, I'm sure!
ChrisA
ChrisA
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Function docstring as a local variable Chris Angelico <rosuav@gmail.com> - 2011-07-11 04:11 +1000
Re: Function docstring as a local variable Richard Thomas <chardster@gmail.com> - 2011-07-10 14:16 -0700
Re: Function docstring as a local variable python@bdurham.com - 2011-07-10 18:13 -0400
Re: Function docstring as a local variable Roy Smith <roy@panix.com> - 2011-07-10 18:41 -0400
Re: Function docstring as a local variable Tim Johnson <tim@johnsons-web.com> - 2011-07-10 14:50 -0800
Re: Function docstring as a local variable Tim Chase <python.list@tim.thechases.com> - 2011-07-10 18:14 -0500
csiph-web