[Tutor] Regular expressions...

Kent Johnson kent37 at tds.net
Fri May 2 20:16:26 CEST 2008


On Fri, May 2, 2008 at 1:38 PM, Spencer Parker <inthefridge at gmail.com> wrote:
> Well...it gives me the entire path...I am not running this script from the
> actual directory...I am running it from a secure user directory that only
> has certain access rights.  During the os.path.dirname gives me the entire
> directory path...I just need to last part of it is all. out of
> '/xen/domains2/machinename/disk.img all I need is 'machinename'

In [1]: import os

In [2]: path = '/xen/domains2/machinename/disk.img'

In [3]: os.path.basename(os.path.dirname(path))
Out[3]: 'machinename'

Kent


More information about the Tutor mailing list