How to: get list of modules in a package

Dan Perl danperl at rogers.com
Tue Oct 12 13:44:56 EDT 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 
understand.

Dan

"Mike C. Fletcher" <mcfletch at rogers.com> wrote in message 
news:mailman.4757.1097594848.5135.python-list at python.org...
> 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
>  http://www.vrplumber.com
>  http://blog.vrplumber.com
> 





More information about the Python-list mailing list