How to: get list of modules in a package

Dan Perl danperl at
Tue Oct 12 19:44:56 CEST 2004

What a tease!  "It definitely has been done in the past", so there must be a 
way, but you're not telling us how you did that!  :-)

Oh well, I have another solution (based on os.listdir) and even if it is not 
the most elegant one that could exist, at least it's going to be clear to 


"Mike C. Fletcher" <mcfletch at> wrote in message 
news:mailman.4757.1097594848.5135.python-list at
> Peter L Hansen wrote:
> ...
>> Given the dynamic nature of Python, I doubt that's easy to do.
>> I'm not sure even os.listdir(), for example, can be relied on,
>> given that you can import modules from zip files, or if the
>> import hook is used, even from remote locations or, presumably
>> (though I haven't seen it done yet), from "thin air" where
>> the module is generated dynamically.
> I used to do this somewhere in mcf.vrml (old VRML97 processing package). 
> The idea was to generate a module to hold classes which were also 
> generated on-the-fly (from VRML97 prototypes).  You could then import the 
> classes from the non-existent module as long as the module itself (which 
> roughly corresponded to a VRML97 file) was part of your pickle.  The 
> package holding those modules was empty until such time as you either 
> generated one of those modules or loaded one from a pickle, and there was 
> just no reasonable way to know what would eventually show up there.
> Advances in Python (and my moving away from my perverse love of such 
> tricks ;) ) made that particular usage obsolete, but it definitely has 
> been done in the past...
> Enjoy,
> Mike
> ________________________________________________
>  Mike C. Fletcher
>  Designer, VR Plumber, Coder

More information about the Python-list mailing list