Python 3.x tracer.run(';main()';)报告名称错误
我正在阅读并得到了一个关于Python 3.x tracer.run(';main()';)报告名称错误,python-3.x,Python 3.x,我正在阅读并得到了一个关于 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
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()的执行情况,因此需要显示函数main()才能成功运行本例您是否创建了
main()
function?ty。明白了,但又臭又有趣的例子。