importing modules with the same name but from different directories

Mirko Koenig koenig at v-i-t.de
Sun Apr 20 21:25:34 EDT 2003


Hi

The subject is a little bit long but i didn't how how to describe it
shortly.

I hope my english is good enough to explain my problem.

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.

In modul1 i wrote sys.path.append( "./languages" ) then import german.
In modul2 i wrote the same. I know in that way it coulnd't work.

What can i do, that every modul knows its 'homedir', no matter from where
i start it ?

I don't want to set environment variables, because the programm is for
beginners, that are not used to pc's and want an easy going programm and
not to set env vars.

I'm developing under linux if that help solving my problem

thanx for comments

Mirko Koenig




More information about the Python-list mailing list