0

I need to find a file contains the module from an egg file.

For example: module_name = "plugins" And the return file within the egg file: "mypackage/plugins.py"

How to do that without importing the module?

Sean Nguyen
  • 12,528
  • 22
  • 74
  • 113

1 Answers1

0

Assuming I understand the question..

Just use importlib and try to import the module.

from importlib import import_module

package_name = "mypackage"
try:
     module = import_module("{}.{}".format(package_name, "plugins")
except ImportError:
     # The module does not exist

If the module is importable, module will contain a reference to the initialised module. module.__file__ will also give you the path to the python file.

Grimmy
  • 3,992
  • 22
  • 25