dir = '/xen/domains2/machinename/disk.img' a = dir.split('/')[3] is what I would use...
On Fri, May 2, 2008 at 12:38 PM, Spencer Parker <[EMAIL PROTECTED]> 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' > > On Fri, May 2, 2008 at 10:23 AM, Kent Johnson <[EMAIL PROTECTED]> wrote: > > > On Fri, May 2, 2008 at 12:08 PM, Spencer Parker <[EMAIL PROTECTED]> > > wrote: > > > I need to use a regular expression to get a couple of items for my > > python > > > script. So far the script is running an 'ls' command to get a few > > items > > > that I need > > > > > > I run an 'ls -sk /xen/domains2/machinename/disk.img' > > > > > > Output > > > > > > 2454112 /xen/domains2/machinename/disk.img > > > > Look at os.path.getsize(). You don't need to use ls to get this > > information. > > > > > What I need to get is just the size numbers using regular expressions. > > > > You could just use str.split() but getsize() is better. > > > > > I also need to get the 'machinename' > > > portion of the path as well to stick into the database. > > > > Don't you already know this? Where does the ls command come from? > > Anyway look at os.path.split() and os.path.dirname(). > > > > Kent > > > > > > -- > Spencer Parker > _______________________________________________________ > > "if you can't go to heaven, may you at least die in Ireland." > > _______________________________________________________ > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > >
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor