简体   繁体   English

如何打印python模块层次结构?

[英]How to print python module hierarchy?

I have a file which is dynamically loaded. 我有一个动态加载的文件。 Because of the dynamic loading, I have no idea what its module path is, and all of my best guesses (per the filesystem structure) have failed so far. 由于动态加载,我不知道它的模块路径是什么,到目前为止(根据文件系统结构)我所有的最佳猜测都失败了。

  1. How do I inspect the full module path from within the running file? 如何从正在运行的文件中检查完整的模块路径?
  2. How do I walk the hierarchy programmatically? 如何以编程方式遍历层次结构?

(Python 2.6) (Python 2.6)

If you're able to import that module runtime anyways you have the access to __file__ attribute of it, which will give you the exact location of your module. 如果仍然能够导入该模块运行时,则可以访问其__file__属性,这将为您提供模块的确切位置。

for example: 例如:

In [1]: import os

In [2]: print os.path.dirname(os.__file__)
/usr/lib/python2.7

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

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