Packages "inside" modules

I have an increasing number of scripts that make up the program I'm writing, and decided it was time to clear the source tree and pack them correctly. I am sure this is a simple question, but I cannot figure out how to do this.

If I have a group of modules that fit together, but one of them should be a top-level module, and the rest should have a module name prefix, but actually go to lower-level packages, how can I do this.

For example, I would like to be able to import mystuffreceive all the sacrament. but I must also have the opportunity import mystuff.test.test1. I thought I would create a source tree like this,

myprogram/
    mystuff.py
    mystuff/
        __init__.py
        tests/
            __init__.py
            test1.py
            test2.py
            ...

But in this case, it seems that it mystuff/always takes precedence over mystuff.py, so import mystuffit does nothing (so far it is mystuff/ __init__.pyempty).

What will be the right approach to get the desired behavior? Or is it impossible, and I have to move mystuff.pyin mystuff/and access it like mystuff.mystuff(seems like an unnecessary repetition).

Sorry if I just missed something obvious. I suppose this should be documented somewhere, but I cannot find where somewhere.

. , , ! , , __init__.py, . , , , mystuff.py mystuff/__init__.py. - - , , .

, , , distutils tar.gz, . .

+5
2

mystuff.py mystuff/__init__.py .

+4

mystuff.py mystuff/.

:

  • mystuff.py mystuff/__init__.py
  • mystuff.py, , mystuff/_stuff.py, mystuff/__init__.py.

:

myprogram/
    mystuff.py -------
    mystuff/           \
        __init__.py    /
        _stuff.py <---
        tests/
            __init__.py
            test1.py
            test2.py
            ...

mystuff/__init__.py :

from mystuff._stuff import *
+4

All Articles