Getting a list of all modules

Chris Angelico rosuav at gmail.com
Wed Jul 30 15:27:42 CEST 2014


On Wed, Jul 30, 2014 at 11:22 PM, Leo Jay <python.leojay at gmail.com> wrote:
> On Wed, Jul 30, 2014 at 3:43 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>> I'm looking for a programmatic way to get a list of all Python modules
>> and packages. Not just those already imported, but all those which
>> *could* be imported.
>>
>
> If you don't actually import it, how can you know it could be imported?
> Not all .so files are valid python modules.
> Not all .py files could be imported by all python interpreters.

What if you define it as "modules you could attempt to import"? Sure,
any module might fail during importing, but you've still taken a
statement of "import spam" and turned it into an attempt to read some
specific file from the disk.

ChrisA



More information about the Python-list mailing list