Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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; 'interpreter': 0.05; 'subject:position': 0.05; 'python': 0.08; '%s"': 0.09; 'subject:string': 0.09; 'def': 0.13; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message- id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'subject:function': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'cc:no real name:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'string': 0.24; 'cc:2**0': 0.24; 'traceback': 0.24; 'function': 0.27; 'import': 0.27; 'print': 0.29; 'cc:addr:python.org': 0.29; 'subject:?': 0.31; 'header:User-Agent:1': 0.33; 'subject:How': 0.35; 'subject:from': 0.38; 'results': 0.63; 'levels': 0.64; 'subject:name': 0.67 Date: Fri, 30 Dec 2011 12:35:53 -0600 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16 MIME-Version: 1.0 To: dmitrey Subject: Re: How to get function string name from i-th stack position? References: <00667d71-b9bc-411d-b2bc-0ead1d1468d7@g41g2000yqa.googlegroups.com> In-Reply-To: <00667d71-b9bc-411d-b2bc-0ead1d1468d7@g41g2000yqa.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Source: X-Source-Args: X-Source-Dir: Cc: python-list@python.org 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1325270163 news.xs4all.nl 6916 [2001:888:2000:d::a6]:55059 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18221 On 12/30/11 11:51, dmitrey wrote: > how to get string name of a function that is n levels above > the current Python interpreter position? Use the results of traceback.extract_stack() from traceback import extract_stack def one(x): print "one", x stk = extract_stack() for mod, lineno, fun_name, call_code_text in stk: print "[%s:%i] in %s" % (mod, lineno, fun_name) def two(x): print "two", x one(x) def three(x): print "three", x two(x) three("Hi") -tkc