package structure?

Benjamin Kaplan benjamin.kaplan at case.edu
Sun Dec 14 21:27:57 CET 2008


On Sun, Dec 14, 2008 at 3:16 PM, Torsten Mohr <tmohr at s.netic.de> wrote:

> 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.
>

You have two modules named smod1- one of them uses the code in smod1.py, the
other one is in smod1/__init__.py. The second one hides the first. Python
doesn't let you have two modules with the same name. You have to either
rename one of the smod1's or define AClass in smod1/__init__.py instead.


>
>
> Thanks for any hints,
> Torsten.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081214/423e095f/attachment.html>


More information about the Python-list mailing list