Binu K S
binux.lists at gmail.com
Mon Dec 13 08:39:45 CET 2004
sys.path will contain the path to the script.
>From the sys module documentation:
"As initialized upon program startup, the first item of this list,
path, is the directory containing the script that was used to
invoke the Python interpreter. If the script directory is not
available (e.g. if the interpreter is invoked interactively or if the
script is read from standard input), path is the empty string,
which directs Python to search modules in the current directory first.
Notice that the script directory is inserted before the entries
inserted as a result of PYTHONPATH."
On Mon, 13 Dec 2004 18:03:30 +1100, Lars Yencken <lljy at internode.on.net> wrote:
> Hi Binu,
> On 13/12/2004, at 4:11 PM, Binu K S wrote:
> > This should get you the module's path:
> > import sys
> > sys.modules['rpy'].__file__
> Unfortunately it's not the rpy module itself whose path I'm looking
> for. It's the absolute path of my module that I've created.
> If my script was called runRScript.py, and it was in the same directory
> as someScript.r, I'm only able to get it working if I run
> python runRScript.py
> from the same directory. In otherwords, I can't be in a child directory
> and run:
> python ../runRScript.py
> because runRScript depends internally on the file someScript.r, and
> can't find it.
> I've found a pathconf module posted earlier to this group, which does
> half the job. Unfortunately, when I call get_rootdir() it returns
> '/usr/bin' instead of my project's root directory ;(
More information about the Python-list