package structure?

T

Torsten Mohr

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

Arnaud Delobelle

Torsten Mohr said:
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
 
T

Torsten Mohr

I wonder how i can make AClass() known in that package.
Why don't you put the contents of smod1.py in mod/smod1/__init__.py?
It'll work this way.

Of course, thanks for that hint.


Best regards,
Torsten.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,823
Latest member
Nadia88

Latest Threads

Top