[Tutor] Regular expressions...

jay titleistfour at gmail.com
Fri May 2 19:46:06 CEST 2008


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 <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'
>
> On Fri, May 2, 2008 at 10:23 AM, Kent Johnson <kent37 at tds.net> wrote:
>
> > On Fri, May 2, 2008 at 12:08 PM, Spencer Parker <inthefridge at gmail.com>
> > 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 at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080502/b6c53454/attachment.htm>


More information about the Tutor mailing list