|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help with string manipulation
I have this:
Code:
import commands
info = commands.getoutput('df /var')
print info
I need to only print the value under Use% such as 62%. Could someone assist me with this please? Thank You, Laura |
|
#2
|
||||
|
||||
|
Hey Laura,
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 .Code:
>>> import commands
>>> info = commands.getoutput('df /var')
>>> info
'Filesystem 512-blocks Used Avail Capacity Mounted on\n/dev/disk0s3 116948016 14353216 102082800 12% /'
>>> info.split()
['Filesystem', '512-blocks', 'Used', 'Avail', 'Capacity', 'Mounted', 'on', '/dev/disk0s3', '116948016', '14353216', '102082800', '12%', '/']
>>> data = info.split()
>>> print data[-2]
12%
>>>
Take care, Mark .Last edited by netytan : November 8th, 2004 at 02:01 PM. |
|
#3
|
|||
|
|||
|
Thank you so much it works perfectly.
Laura |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Need help with string manipulation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|