Maybe a dumb question
gherron at islandtraining.com
Wed Sep 11 03:28:02 CEST 2002
On Tuesday 10 September 2002 02:58 pm, Fabien HENON wrote:
> I have written an editor for Povray using Python, Tkinter and Pmw
> It is available at :
> The software includes one main file and 6 others which are for the
> language customization. People can choose between French, English,
> All the translations for these languages are stored in files called
> menu_francais.py, menu_english.py, menu_deutsch.py ....when the editor
> is started.
> I would like to clean the directory a bit and put all these 'languages
> files' into a sub-directory called Lang.
> How do I tell python to look into a particular sub-directory when
> importing a file.
> I tried the os.path.join syntax, but to no avail.
1. You can manipulate the search path for imports thus:
langDir = '...whatever...'
where the calculation of the path to the language directory is
thisPyFile = os.path.join(os.getcwd(), sys.argv)
thisDir = os.path.normpath(os.path.dirname(thisPyFile))
langDir = os.path.join(thisDir, 'Lang')
2. Use the package interface for the directory Lang:
Create an empty file Lang/__init__.py. Then you can import
Lang/menu_francais.py like this:
Look through the standard library for many examples of (non empty)
More information about the Python-list