importing modules with the same name but from different directories
Peter Hansen
peter at engcorp.com
Sun Apr 20 21:52:22 EDT 2003
Mirko Koenig wrote:
>
> 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.
Although it's not 100% clear to me what you are trying to do, I'd
like to suggest a couple of alternatives to what you seem to be
trying, which might be simpler.
Option 1 is to just use the execfile() builtin function to execute
the necessary files, rather than trying to use "import".
Option 2 is to rename the files to something other than .py and
load them as regular files, then decode them with exec().
Option 3 is to find one of the standard tools for supporting
internationalization and use a standard approach instead of
rolling your own like this. Check the "gettext" standard
library module for details.
-Peter
More information about the Python-list
mailing list