简体   繁体   English

Python:计数模块导入?

[英]Python : counting module imports?

I am a mid end python developer at an animation studio, and have been presented with a unique diagnostics request ; 我是动画工作室的中端Python开发人员,并且被提出了独特的诊断要求;

To assess what code gets used and what doesn't. 评估使用什么代码,不使用什么代码。

Within the sprawling disorganized structure of Python modules importing modules : I need to count the python modules that are imported, and possibly at a deeper level, find which methods are called. 在庞大的无序的Python模块导入模块结构中:我需要计算导入的python模块,并可能在更深的层次上找到被调用的方法。

As far as finding out which methods are called, I think that would be easy to solve by writing my own logging metaclass. 至于找出哪些方法被调用,我认为通过编写自己的日志记录元类很容易解决。

However, I'm at loss to imagine how I should count or log module imports at varying depths. 但是,我不知所措,我该如何计算或记录不同深度的模块导入。

Thanks for any ideas you may have. 感谢您的任何想法。

If you have a way to exercise the code, you can run the code under coverage.py . 如果您有执行代码的方法,则可以在coverage.py下运行代码。 It's normally used for testing, but its basic function would work here: it indicates what lines of code are run and what are not. 它通常用于测试,但是它的基本功能在这里可以正常工作:它指示运行哪些代码行,哪些不运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM