Get module source

Hello folks,

For (insert whatever reasons) purposes, I’m trying to get the source code of a custom module.
For any other module, I could just import it and use inspect.getsource(module), but it doesn’t work for home made ones. Because they’re not basic modules:

Any idea how I could work around that ?

Hey I think I got it, I may have asked too soon:


seems to print the actual module’s code.

Note that foo.code seems to fail if foo contains from bar import *, in which case it returns the code from bar instead.