python-3.x - tracer.run('main()') 报告名称错误
问题描述
我正在阅读https://docs.python.org/3.7/library/trace.html并获得了演示示例
import sys
import trace
# create a Trace object, telling it what to ignore, and whether to
# do tracing or line-counting or both.
tracer = trace.Trace(
ignoredirs=[sys.prefix, sys.exec_prefix],
trace=0,
count=1)
# run the new command using the given tracer
tracer.run('main()')
# make a report, placing output in the current directory
r = tracer.results()
r.write_results(show_missing=True, coverdir=".")
运行它并得到错误
NameError: name 'main' is not defined
这样一个愚蠢的例子的目的是什么?
解决方案
您需要有一个名为 main 的函数才能使示例正常工作。在示例中,您正在跟踪函数 main() 的执行,因此需要存在它才能成功运行示例
推荐阅读
- c - (C, ncurses) 在特定坐标读取字符
- java - com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException:患者;没有 HASH 键的映射
- javascript - 所有输入都触发了点击事件,而不仅仅是被点击的那个
- r - 将 csv 文件读取为矩阵并在 R 中使用条件 if 更改条目
- node.js - 将 VSCode 设置为转译 typescript 并通过按 F5 开始使用 NodeJS 进行调试?
- tensorflow - 如何解决tensorflow jit编译错误
- unity3d - unity 检查鼠标悬停在哪个对象上
- angular - ABP 框架创建的 Angular 项目,登录和用户管理不起作用
- python - 将字典中的值与输入数字进行比较
- unity3d - Unity Rewarded Interstitial with Google Mobile Ads v6.0.2 - 教程中的代码不起作用