Maybe a dumb question

Gary Herron gherron at
Tue Sep 10 21:28:02 EDT 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,
> German,...
> All the translations for these languages are stored in files called
>,, ....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.

Two possibilities:

1.  You can manipulate the search path for imports thus:

    import sys
    langDir = '...whatever...'
    import Whatever

  where the calculation of the path to the language directory is
  something like:

    thisPyFile = os.path.join(os.getcwd(), sys.argv[0])
    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/  Then you can import
  Lang/ like this:


  Look through the standard library for many examples of (non empty) files.

Gary Herron

More information about the Python-list mailing list