recursive import list

Philippe C. Martin philippe at philippecmartin.com
Tue Jun 14 08:37:45 EDT 2005


Mike Meyer wrote:

> "wittempj at hotmail.com" <martin.witte at gmail.com> writes:
>>> I have a fairly large project going on and would like to figure out
>>> automatically from the source which files are being imported.
>> If you use your own import function, like below, you could create a
>> list of all imported modules.
> 
> Why not use sys.modules? To answer the question actually asked, check
> for a __file__ attributes on each module in sys.modules, and print
> that if it exists.
> 
> That won't list builtin modules that are imported - but they don't
> have files to be imported, so I assume that the OP doesn't want them
> listed.
> 
>         <mike


Thanks to both, I'll try this.

My goal would have been to just launch the "recipe" on the main module, and
get the list for all modules.

Regards,

Philippe




More information about the Python-list mailing list