在Python中保存痕量功能的结果

发布于 2025-02-09 17:01:02 字数 662 浏览 2 评论 0 原文

我正在尝试使用Python使用以下代码提供的“跟踪”功能来找出一些记录信息。

tracer = trace.Trace(
ignoredirs=[sys.prefix, sys.exec_prefix],
trace=False,
countfuncs = True,
count=False,
timing = True)
tracer.run('exec(script, variables, variables)')

# make a report, placing output in the current directory
r = tracer.results()
r.write_results(show_missing=True,coverdir='trace_vizier')

跟踪结果在终端中打印出来,但是未生成保存数据的文件。

有人可以告诉我为什么会发生这种情况吗?

注意 - https://docs.python.org/3/library/library/trace.html (跟踪功能)

I'm trying to find out some logging information using 'trace' function provided by python using the following code.

tracer = trace.Trace(
ignoredirs=[sys.prefix, sys.exec_prefix],
trace=False,
countfuncs = True,
count=False,
timing = True)
tracer.run('exec(script, variables, variables)')

# make a report, placing output in the current directory
r = tracer.results()
r.write_results(show_missing=True,coverdir='trace_vizier')

The trace results are getting printed in the terminal but the file where data is saved is not generated.

Could someone tell me why this is happening?

Note - https://docs.python.org/3/library/trace.html (Trace function)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆夏时光 2025-02-16 17:01:02

看来它与将内置的函数放置为从跟踪中运行方法的命令有关,并且与参数 countfuncs and count count 接收到。
这是我所做的:

从参数中,跟踪构造器接收 countfuncs count to countfuncs = false,count = true
下一个将exec(脚本,变量,变量)'在您自己的函数内部,然后将其传递到运行方法中。

一个例子:

def test(x):
    exec(x)

tracer = trace.Trace(
ignoredirs=[sys.prefix, sys.exec_prefix],
trace=False,
countfuncs = False,
count=True,
timing = True)
x = 'print("asdf")'
tracer.run('test(x)')

# make a report, placing output in the current directory
r = tracer.results()
r.write_results(show_missing=True,coverdir='trace_vizier')

It appears that It has something to do with putting in-builts functions as command for the run method from Trace, and with the arguments countfuncs and count that the Trace constructor receives.
Here is what I did:

From the arguments the Trace constructor receives change countfuncs and count to countfuncs = False, count=True.
Next put exec(script, variables, variables)' inside a function of your own and pass it into the run method.

An example:

def test(x):
    exec(x)

tracer = trace.Trace(
ignoredirs=[sys.prefix, sys.exec_prefix],
trace=False,
countfuncs = False,
count=True,
timing = True)
x = 'print("asdf")'
tracer.run('test(x)')

# make a report, placing output in the current directory
r = tracer.results()
r.write_results(show_missing=True,coverdir='trace_vizier')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文