如何知道哪个文件在调用哪个文件,文件系统

2024-10-08 19:19:13 发布

您现在位置:Python中文网/ 问答频道 /正文

如何知道哪个文件正在调用文件系统中的哪个文件,例如file1.exe正在调用file2.exe
因此file2.exe被修改,
在日志文件中输入file1.exe。你知道吗

酒鬼

我在网上搜索过,但找不到任何样品。你知道吗


Tags: 文件样品exefile1file2酒鬼
1条回答
网友
1楼 · 发布于 2024-10-08 19:19:13

为了知道哪个文件正在调用哪个文件,您可以使用跟踪模块

如果你有两个文件

***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='.')

相关问题 更多 >

    热门问题