Help with paths

Alexander Kapps alex.kapps at web.de
Mon Oct 18 17:43:23 EDT 2010


On 18.10.2010 23:24, Devin M 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.
>
> Regards,
> Devin M

os.path.split() is designed for this

In [4]: path="/home/devinm/project/files"

In [5]: import os.path

In [6]: os.path.split(path)[0]
Out[6]: '/home/devinm/project'



More information about the Python-list mailing list