【发布时间】:2017-02-17 13:44:33
【问题描述】:
我想获得我的模块(列出所有函数名称),即使在使用 cProfile 时也是如此。我该怎么做?
为了澄清我在自己的模块中使用了一些自省,但是sys.modules[__main__] 在使用-m cProfile 运行时当然不会再返回我自己的模块。
要重现,请创建 modtest.py:
#!/usr/bin/env python3
import sys
print(sys.modules[__name__])
像这样运行它:
$ ./modtest.py
<module '__main__' from './modtest.py'>
$ python -m cProfile ./modtest.py
<module 'cProfile' from '...cProfile.py'>
我怎样才能让最后一行写成from './modtest.py'?
【问题讨论】:
标签: python python-3.x python-module cprofile