开发者社区> 问答> 正文

执行tracer.run('main()')时报nameError异常

代码如下:

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

展开
收起
安忆333 2019-12-05 15:44:30 1722 0
1 条回答
写回答
取消 提交回答
  • 你必须有一个名为main的函数,该示例才能正常工作。 在示例中,您正在跟踪函数main()的执行,因此需要存在该函数才能成功运行示例

    2019-12-05 15:45:19
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载