如何在Python中找到所有子模块? [英] How to find all child modules in Python?

查看:207
本文介绍了如何在Python中找到所有子模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然在Python中将子"模块导入另一个模块并列出其属性相当简单,但是当您要导入 all 个子模块时,难度会稍微增加.

While it is fairly trivial in Python to import a "child" module into another module and list its attributes, it becomes slightly more difficult when you want to import all child modules.

我正在为现有3D应用程序构建工具库.每个工具都有其自己的菜单项和子菜单.我希望该工具负责创建其自己的菜单,因为其中许多菜单都是根据上下文和模板进行更改的.我希望基本模块能够找到所有子模块,并检查create_menu()函数并在找到它后调用它.

I'm building a library of tools for an existing 3D application. Each tool has its own menu item and sub menus. I'd like the tool to be responsible for creating its own menus as many of them change based on context and templates. I'd like my base module to be able to find all child modules and check for a create_menu() function and call it if it finds it.

发现所有子模块的最简单方法是什么?

What is the easiest way to discover all child modules?

推荐答案

使用 dir( ) imp模块

这篇关于如何在Python中找到所有子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆