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



--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to