[Tutor] strip and split?

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Sat Nov 30 22:32:57 CET 2013


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

and it should give you what you want.

Best,
Wolfgang





More information about the Tutor mailing list