Path problem

Binu K S binux.lists at gmail.com
Mon Dec 13 00:11:12 EST 2004


This should get you the module's path:

import sys
sys.modules['rpy'].__file__

On Mon, 13 Dec 2004 15:48:29 +1100, Lars Yencken <lljy at internode.on.net> wrote:
> Hello,
> 
> I'm working on a project where my python modules are using persistent
> files in the same directory. As an example, we're using rpy, so a piece
> of python code might read:
> 
>         from rpy import *
> 
>         rScript = 'myScript.r'
> 
>         r.source(rScript)
> 
> Now the problem with this is that when I run this from the directory
> above, or any other directory than the directory containing the R
> script, this doesn't work, and understandably too.
> 
> Is there some easy way to get around this? I can't (and don't want to)
> hard code paths, since they'll be different on every workspace I check
> out from the repository.
> 
> If there's a way that I can get the directory of the module file
> itself, then that's all I need to fix this for good.
> 
> Thanks,
> Lars
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list