Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18221
| Date | 2011-12-30 12:35 -0600 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: How to get function string name from i-th stack position? |
| References | <00667d71-b9bc-411d-b2bc-0ead1d1468d7@g41g2000yqa.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4250.1325270163.27778.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to get function string name from i-th stack position? dmitrey <dmitrey15@gmail.com> - 2011-12-30 09:51 -0800
Re: How to get function string name from i-th stack position? Tim Chase <python.list@tim.thechases.com> - 2011-12-30 12:35 -0600
Re: How to get function string name from i-th stack position? dmitrey <dmitrey15@gmail.com> - 2011-12-30 10:43 -0800
Re: How to get function string name from i-th stack position? Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-30 14:48 -0700
Re: How to get function string name from i-th stack position? dmitrey <dmitrey15@gmail.com> - 2011-12-31 00:44 -0800
Re: How to get function string name from i-th stack position? Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-31 10:13 -0700
Re: How to get function string name from i-th stack position? Lie Ryan <lie.1296@gmail.com> - 2011-12-31 22:41 +1100
Re: How to get function string name from i-th stack position? Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-31 10:05 -0700
csiph-web