Can you help me to find some good examples for importlib? I remember seeing one that loaded modules from sqlite, and one that loaded from the network, but I can’t find it now. It would need to be complete enough that https://docs.python.org/3/library/inspect.html#inspect.getsourcelines
works. Related question:
You might want to have a look at the code for https://aroberge.github.io/ideas/docs/html/.
One example about loading code from the network is included in the latest edition of the Python cookbook.
Thanks.
It looks like I can make the code do what I want if I inherit from SourceLoader
instead of InspectLoader
. The get_data()
method is used to execute the module, and get_source()
is only called when the source code needs to be displayed. Even though inspect.getsource(module)
works for InspectLoader
, that source code is not shown by pdb
or in tracebacks until we inherit from SourceLoader
instead of InspectLoader
.