3

是否可以在回溯中获取连续行的所有行?

例子:

#! /usr/bin/env python
def function_with_long_name(foo, bar):
  raise Exception('problem?')
function_with_long_name('very_important_value',
  'meaningless_value')

输出:

$ ./test.py 
Traceback (most recent call last):
  File "./test.py", line 5, in <module>
    'meaningless_value')
  File "./test.py", line 3, in function_with_long_name
    raise Exception('problem?')
Exception: problem?

请注意,它只打印续行的最后一行。

我想要续行的所有行,如下所示:

$ ./test.py 
Traceback (most recent call last):
  File "./test.py", line 5, in <module>
    function_with_long_name('very_important_value',
      'meaningless_value')
  File "./test.py", line 3, in function_with_long_name
    raise Exception('problem?')
Exception: problem?

这可能吗?

我查看了traceback模块,但它返回的值已经被截断。

例子:

#! /usr/bin/env python
import traceback
def function_with_long_name(foo, bar):
  print traceback.extract_stack()
function_with_long_name('very_important_value',
  'meaningless_value')

输出:

$ ./test.py 
[('./test.py', 6, '<module>', "'meaningless_value')"), ('./test.py', 4, 'function_with_long_name', 'print traceback.extract_stack()')]
4

1 回答 1

1

似乎有人刚刚为此打开了Python 问题 12458。建议你跟着那里。

于 2011-10-02T18:19:12.567 回答