import package w/ all subpackages?

Michael McFarland sidlonDoesntLikeSpam at yahoo.com
Sun Mar 30 16:04:29 EST 2003


    My main problem w/ using the __init__.py file is that, while 'from
foolib import baz' works properly, 'import foolib.baz' doesn't.  (ie, it
imports all other subpackages/modules which were imported by the
__init__.py)

   Carl's solution would certainly work for when I want *my* code to import
a full package (although I still don't think "foolib =
import_fully('foolib')" looks as clean as "import fully foolib").  But I'm
thinking in terms of making the interface to my complex package as useful as
possible to other people (who won't have access to this 'import_fully'
function).  I suspect that over time, as more python packages grow (like the
'mx' package), there will be more of a need for all python users to have
some built-in way of doing a "import fully mx".

   Anyway, thank you both for your input!  B^)

   - Michael


> Hi,
>
> imho you should put the imports into __init__ since one can still select
if
> he does not want to import all stuff by means of:
>
> from foolib import baz
>
> Ciao Ulrich






More information about the Python-list mailing list