[Distutils] modules in different folders but under same namespace

Tarek Ziadé ziade.tarek at gmail.com
Thu Feb 4 18:24:43 CET 2010


On Thu, Feb 4, 2010 at 6:11 PM, Robert Kern <robert.kern at gmail.com> wrote:
> On 2010-02-04 11:05 AM, Tarek Ziadé wrote:
>>
>> On Thu, Feb 4, 2010 at 5:53 PM, Riccardo-Maria BIANCHI
>> <riccardo.maria.bianchi at cern.ch>  wrote:
>>>
>>> Hi,
>>
>> Hi,
>>
>>>
>>> I have a package structured like this:
>>>
>>>
>>> package/__init__.py
>>>   src/ __init__.py
>>>          mod1.py
>>>   share/__init__.py
>>>            mod2.py
>>>
>>>
>>> Now I can import them as:
>>> package.src.mod1
>>> package.share.mod2
>>>
>>> How can I use Distutils to be able to import both of them under the same
>>> "package" namespace as:
>>>
>>> import package.mod1
>>> import package.mod2
>>
>> unrelated to Distutils but,
>>
>> What you can do is add these line in package/__init__.py :
>>
>>   from package.src import mod1
>>   from package.share import mod2
>>
>> Beware though, that this means the modules will be loaded
>> even if "import package" is called, which could have some unwanted
>> side effects depending on the code.
>
> This does not work. You cannot "import package.mod1" under this scenario.

Right, only "from package import mod1" works.

Not sure why you want to remove the __init__.py files in sub and share
in your solution though.

-- 
Tarek Ziadé | http://ziade.org


More information about the Distutils-SIG mailing list