November 8th, 2004, 01:37 PM
Need help with string manipulation
I have this:
I need to only print the value under Use% such as 62%.
info = commands.getoutput('df /var')
Could someone assist me with this please?
November 8th, 2004, 01:56 PM
Just follow the example and you should be able to see what's going on; simply I've split the commands output then only printed the part you wanted (-2). There are of course other ways to do this, this is just my preference .
>>> import commands
>>> info = commands.getoutput('df /var')
'Filesystem 512-blocks Used Avail Capacity Mounted on\n/dev/disk0s3 116948016 14353216 102082800 12% /'
['Filesystem', '512-blocks', 'Used', 'Avail', 'Capacity', 'Mounted', 'on', '/dev/disk0s3', '116948016', '14353216', '102082800', '12%', '/']
>>> data = info.split()
>>> print data[-2]
Last edited by netytan; November 8th, 2004 at 02:01 PM.
November 8th, 2004, 02:02 PM
Thank you so much it works perfectly.