Python's trace module and filepaths

南笙酒味 提交于 2019-12-06 09:51:59

It wasn't very obvious, but I've found that if I use the countfuncs parameter in trace, or the --listfuncs parameter if I'm using trace from the command line, I get full path names. Thus, for the program:

import trace
from recurse import recurse

tracer = trace.Trace(count=False, trace=True, countfuncs=True)
tracer.run('recurse(2)')
tracer.results().write_results()

... (using Doug Hellmann's example from here) I get the following output:

functions called:
filename: <string>, modulename: <string>, funcname: <module>
filename: C:\Python33\lib\encodings\cp850.py, modulename: cp850, funcname: IncrementalEncoder.encode
filename: C:\Python33\lib\trace.py, modulename: trace, funcname: _unsettrace
filename: C:\usr\sjl\dev\test\python\recurse.py, modulename: recurse, funcname: recurse

This isn't quite what you were looking for because you can see it is ignoring the instruction to trace the lines of code, so it doesn't give the file path next to those lines of code. However, it does tell you exactly which files were being used by the Python script.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!