package structure?

Arnaud Delobelle arnodel at googlemail.com
Sun Dec 14 15:35:09 EST 2008


Torsten Mohr <tmohr at s.netic.de> writes:

> Hi,
>
> in a package i'd like to have a structure like this:
>
> Files end with ".py", others are directories:
>
> mod
>   __init__.py       # sets __all__ = ['smod1']
>   smod1.py          # contains AClass()
>   smod1
>     __init__.py     # sets __all__ = ['abc', 'def']
>     abc.py
>     def.py
>
> So i can now do:
>
> import mod.smod1.abc
> import mod.smod1
>
>
> But functions/classes in smod1.py are not found:
>
> a = mod.smod1.AClass()
>
> I know this is somehow ambiguous, but i wonder how else i can make
> "mod" have subpackages and modules.
>
> I wonder how i can make AClass() known in that package.
>
>
> Thanks for any hints,
> Torsten.

Why don't you put the contents of smod1.py in mod/smod1/__init__.py?
It'll work this way.  Or you can put smod1.py within mod/smod1 and put

    from smod1 import *

in mod/smod1/__init__.py

HTH

-- 
Arnaud



More information about the Python-list mailing list