importing modules with the same name but from different directories
Mirko Koenig
koenig at v-i-t.de
Mon Apr 21 08:50:01 EDT 2003
On Mon, 21 Apr 2003 04:42:51 +0200, logistix wrote:
>> -----Original Message-----
>> From: python-list-admin at python.org
>> [mailto:python-list-admin at python.org] On Behalf Of Mirko Koenig Sent:
>> Sunday, April 20, 2003 9:26 PM
>> To: python-list at python.org
>> Subject: importing modules with the same name but from different
>> directories
>>
>> I have a program consisting of many modules. Every modul has its own
>> directory in a directory called modul, eg.
>>
>> .../modul/modul1
>> .../modul/modul2
>>
>> In every modul directory is a diretory for the language files. These
>> files are used to display the modules label in different languages. eg.
>>
>> .../modules/module1/language/german.py
>> .../modules/module1/language/english.py
>> .../modules/module2/language/german.py
>> .../modules/module2/language/english.py
>>
>> My problem is:
>> If is start modul1 from within its modul directory ( .../modules/modul1
>> ) And modul1 calls modul2, then modul2 doesn't load its own language
>> file. Instead it loads the langugae file of modul1.
>>
> Add an __init__.py file to each directory in your project. This makes
> the directories packages. Then you can use a fully qualified path such
> as "import modules.modul1.language.english as module1_english". Note
> that you can't use the same name for different modules at runtime, so
> use "as xxx." to give them a more distinct name.
Is it possible to to something like this:
from modules.modul1 import *
or
from modules.modul1.language.english import text as modul1_text
or
import modules.modul1 as modul1 and than get the languag file
Mirko Koenig
More information about the Python-list
mailing list