2015-08-22 33 views

回答

0

为了知道哪些文件被调用一个文件,你可以使用跟踪模块

EXP:如果你有2个文件

***file1.py*** 
import file2 
def call1(): 
    file2.call2() 

***file2.py*** 
def call2(): 
    print "---------" 

ü可以使用控制台使用它:

$ python -m trace --trackcalls path/to/file1.py 

或在使用跟踪对象的程序中

****tracefile.py*** 
import trace,sys 
from file1 import call1 

#specify what to trace here 
tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix], trace=0, count=1) 
tracer.runfunc(call1) #call the function call1 in fille1 
results = tracer.results() 
results.write_results(summary=True, coverdir='.') 
+0

[http://pymotw.com/2/trace/#tracing-execution],[https://docs.python.org/2/library/trace.html]获取此模块的更多选项 – tparadisez

相关问题