Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'sys': 0.05; '>>>>': 0.09; 'kinda': 0.09; 'object?': 0.09; 'pgp': 0.09; 'subject:Function': 0.09; 'message-----': 0.12; 'am,': 0.13; 'received:209.85.214.174': 0.13; 'received:mail- iw0-f174.google.com': 0.13; 'wrote:': 0.15; '"""find': 0.16; ' -----begin': 0.16; 'except:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hash:': 0.16; 'subject:variable': 0.16; 'test():': 0.16; 'traceback.': 0.16; "hasn't": 0.16; 'mon,': 0.16; 'pm,': 0.16; '>>>': 0.16; 'def': 0.16; 'header:In-Reply-To:1': 0.22; 'worked': 0.24; 'traceback': 0.25; 'function': 0.26; "i'm": 0.27; 'received:209.85.214': 0.28; 'message-id:@mail.gmail.com': 0.28; 'import': 0.29; 'objects.': 0.30; 'print': 0.32; 'signed': 0.32; 'andrew': 0.32; "i've": 0.33; 'to:addr:python-list': 0.34; 'there': 0.34; 'someone': 0.34; '...': 0.34; 'try:': 0.35; 'johnson': 0.35; 'assuming': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:209': 0.40; '11,': 0.68; 'look,': 0.84; 'subject:local': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=LzJaKMnMFkCi8t8fAa8l6YMpYHeQlzkbbRsHVywPDws=; b=sBIqVl/da13YG/TNwnm4fJ9Qf0lFB6Otn/wTU9v4sFcs7IJIcW6INx+l/GwPmfHvQL NEcUfGEiPlhBGrju0JUhYtKrobsxz0Yzg12Uk22J9tszggy45W/yB96tYOzvIZClYytd ZkZgXSf0IJP0H7PbQXPpTErPUlsUMmMeozi9Q= MIME-Version: 1.0 In-Reply-To: <4E19E5A5.5020905@gmail.com> References: <20110710174121.GB12935@johnsons-web.com> <4E19E5A5.5020905@gmail.com> Date: Mon, 11 Jul 2011 04:11:14 +1000 Subject: Re: Function docstring as a local variable From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1310321477 news.xs4all.nl 21790 [2001:888:2000:d::a6]:41657 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:9176 On Mon, Jul 11, 2011 at 3:47 AM, Andrew Berg wr= ote: > -----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(): > ... =A0 =A0 """Hi there.""" > ... =A0 =A0 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=3Dsys.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