Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find all child modules in Python?

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.

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?

like image 800
Soviut Avatar asked May 26 '09 18:05

Soviut


1 Answers

I think the best way to do this sort of plugin thing is using entry_points and the API for querying them.

like image 103
Ross Patterson Avatar answered Oct 06 '22 01:10

Ross Patterson