Help with paths

Andreas Waldenburger usenot at geekmail.INVALID
Mon Oct 18 17:29:11 EDT 2010


On Mon, 18 Oct 2010 14:24:39 -0700 (PDT) Devin M <devinmrn at gmail.com>
wrote:

> Hello, I am using os.path to get the absolute paths of a few
> directories that some python files are in.
> FIlePath = os.path.dirname(os.path.realpath(__file__))
> which returns a path similar to /home/devinm/project/files
> Now I want to get the directory above this one. (/home/devinm/
> project/) Is there a simple way to do this? I was considering spliting
> apart the path and then reconstructing it with the last folder left
> off. Hope theres a better way to do this.
> 
Maybe os.relpath("..", FilePath) ? Python > 2.6 only.

Don't know if that does what you want, but from the description, it
seems to fit:

<http://docs.python.org/library/os.path.html>

os.path.relpath(path[, start])

    Return a relative filepath to path either from the current
    directory or from an optional start point.

    start defaults to os.curdir.


/W

-- 
To reach me via email, replace INVALID with the country code of my home 
country.  But if you spam me, I'll be one sour Kraut.




More information about the Python-list mailing list