Path problem

Binu K S binux.lists at gmail.com
Mon Dec 13 08:39:45 CET 2004


Hi Lars,

sys.path[0] will contain the path to the script.

>From the sys module documentation:
"As initialized upon program startup, the first item of this list,
path[0], 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[0] 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."

-Binu

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 ;(
> 
> Lars
> 
>



More information about the Python-list mailing list