继节目traceback.extract_stack()工作时从类的__init__
方法调用。请发布您的代码,证明它不起作用。包括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)]
>>>
UPDATE而不是看着return a.lib.htmlencode(traceback.extract_stack())
和疑惑,请点击进入管道:
(1)做tb_stack = repr((traceback.extract_stack())
并将结果写入到您的日志文件检查
(2)做return a.lib.htmlencode(some_known_constant_data)
并检查已知数据是否正确显示在您希望显示的位置。