[Tutor] Working Directory
Alexandre Ratti
alex@gabuzomeu.net
Fri, 03 May 2002 20:01:50 +0200
Hi Russell,
At 12:00 03/05/2002 -0400, you wrote:
>Date: Fri, 03 May 2002 10:58:00 +0100
>From: Russell Bungay <rab121@york.ac.uk>
>Subject: [Tutor] Working Directory
>I am currently working on a little app and am having difficulties with
>finding out about what directory I am working in. I need this
>information for two reasons, 1. for the creation and use of a
>ConfigParser object and related file. 2. To import a module held in the
>same directory as the module that I am currently working on.
Here is how I did it in my pet project. Note this project is a package
(i.e. the base dir contains an empty "__init__.py" file):
import os
import yourPackageName
def getAppBaseDir():
"Returns the directory path for the application."
basePath = os.path.dirname(yourPackageName.__file__)
return basePath
This function is stored in a library file that is located in the root
directory of my app. It return the base directory for the app.
Cheers.
Alexandre