[Tutor] strip and split?

Don Jennings dfjennings at gmail.com
Sat Nov 30 22:35:46 CET 2013


On Nov 30, 2013, at 4:32 PM, Wolfgang Maier wrote:

> richard kappler <richkappler <at> gmail.com> writes:
> 
>> 
>> I'm using psutil to generate some somatic data with the following script:
>> 
>> import psutil as ps
>> 
>> cpu = ps.cpu_percent()
>> mem = ps.virtual_memory()
>> disk = ps.disk_usage('/')
>> 
>> All works well, but except for cpu I am struggling to learn how to strip
> out what I don't need.
>> 
>> For example, once I do the above, if I then enter "disk" I get:
>> 
>> disk usage(total=302264549376, used=73844322304, free=213066088448,
> percent=24.4)
>> 
>> So if I want only the number following percent, I get that I need to
> convert this to a built in type and do some split and strip, but that's
> where I'm floundering. Might I get a little guidance on this please?
>> 
> 
> I don't think you have to do any such thing. AFAICT, your code sets disk to
> a usage object that has all the information stored in its attributes. Try, e.g.,
> 
> disk.percent

Yes! I like that much better than my suggestion.

Take care,
Don



More information about the Tutor mailing list