I know that bash -x script.sh
will execute script printing each line before actual execution. How to make Perl and Python interpreters do the same?
我知道bash -x script.sh将在实际执行之前执行脚本打印每一行。如何使Perl和Python解释器做同样的事情?
3 个解决方案
#1
45
Devel::Trace is the Perl analogue, the trace module is Python's.
Devel :: Trace是Perl模拟,跟踪模块是Python的。
#2
4
Devel::DumpTrace
was released in 2011 and has more features than Devel::Trace
, such as evaluating variable values in the trace output.
Devel :: DumpTrace于2011年发布,具有比Devel :: Trace更多的功能,例如在跟踪输出中评估变量值。
#3
3
python -m trace -t main.py
python -m trace -t main.py
Test program:
测试程序:
main.py
main.py
from a import g
def f(i):
g(i)
for i in range(3):
f(i)
a.py
a.py
def g(i):
print i
Output:
输出:
--- modulename: main, funcname: <module>
main.py(1): from a import g
--- modulename: a, funcname: <module>
a.py(1): def g(i):
main.py(2): def f(i):
main.py(4): for i in range(3):
main.py(5): f(i)
--- modulename: main, funcname: f
main.py(3): g(i)
--- modulename: a, funcname: g
a.py(2): print i
0
main.py(4): for i in range(3):
main.py(5): f(i)
--- modulename: main, funcname: f
main.py(3): g(i)
--- modulename: a, funcname: g
a.py(2): print i
1
main.py(4): for i in range(3):
main.py(5): f(i)
--- modulename: main, funcname: f
main.py(3): g(i)
--- modulename: a, funcname: g
a.py(2): print i
2
main.py(4): for i in range(3):
--- modulename: trace, funcname: _unsettrace
trace.py(80): sys.settrace(None)
Tested on Ubuntu 16.10, Python 2.7.12.
在Ubuntu 16.10,Python 2.7.12上测试过。
#1
45
Devel::Trace is the Perl analogue, the trace module is Python's.
Devel :: Trace是Perl模拟,跟踪模块是Python的。
#2
4
Devel::DumpTrace
was released in 2011 and has more features than Devel::Trace
, such as evaluating variable values in the trace output.
Devel :: DumpTrace于2011年发布,具有比Devel :: Trace更多的功能,例如在跟踪输出中评估变量值。
#3
3
python -m trace -t main.py
python -m trace -t main.py
Test program:
测试程序:
main.py
main.py
from a import g
def f(i):
g(i)
for i in range(3):
f(i)
a.py
a.py
def g(i):
print i
Output:
输出:
--- modulename: main, funcname: <module>
main.py(1): from a import g
--- modulename: a, funcname: <module>
a.py(1): def g(i):
main.py(2): def f(i):
main.py(4): for i in range(3):
main.py(5): f(i)
--- modulename: main, funcname: f
main.py(3): g(i)
--- modulename: a, funcname: g
a.py(2): print i
0
main.py(4): for i in range(3):
main.py(5): f(i)
--- modulename: main, funcname: f
main.py(3): g(i)
--- modulename: a, funcname: g
a.py(2): print i
1
main.py(4): for i in range(3):
main.py(5): f(i)
--- modulename: main, funcname: f
main.py(3): g(i)
--- modulename: a, funcname: g
a.py(2): print i
2
main.py(4): for i in range(3):
--- modulename: trace, funcname: _unsettrace
trace.py(80): sys.settrace(None)
Tested on Ubuntu 16.10, Python 2.7.12.
在Ubuntu 16.10,Python 2.7.12上测试过。