下面显示了从类的__init__
方法调用时 traceback.extract_stack() 的工作情况。请发布您的代码,表明它不起作用。包括 Python 版本。不要凭记忆打字;像我一样使用复制/粘贴。
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import traceback as tb
>>> tb.extract_stack()
[('<stdin>', 1, '<module>', None)]
>>> def func():
... print tb.extract_stack()
...
>>> func()
[('<stdin>', 1, '<module>', None), ('<stdin>', 2, 'func', None)]
>>> class Klass(object):
... def __init__(self):
... print tb.extract_stack()
...
>>> k = Klass()
[('<stdin>', 1, '<module>', None), ('<stdin>', 3, '__init__', None)]
>>>
更新而不是看着return a.lib.htmlencode(traceback.extract_stack())
和想知道,进入管道:
(1) 执行tb_stack = repr((traceback.extract_stack())
并将结果写入您的日志文件以进行检查
(2) 执行return a.lib.htmlencode(some_known_constant_data)
并检查已知数据是否正确显示在您期望的位置。