Tuesday, 15 January 2013

python - How remember the whole function result? -



python - How remember the whole function result? -

i want create intelligent discfree indicator.

code:

import os os.system("df -h")

i want utilize regular look (to cutting size in mb), can't, because function returns disk space , value "0".

result = os.system("df -h")

variable "result" "0".

how can access disk space , utilize it?

use subprocess invoking console commands:

import subprocess def command(cmd): try: p = subprocess.popen(cmd, shell = true, stdin = subprocess.pipe, stdout = subprocess.pipe, stderr = subprocess.stdout, close_fds = true) stdout = p.communicate() homecoming stdout[0] except exception ex: raise exception(ex) df = command("df -h") print(df)

which prints:

filesystem size used avail capacity iused ifree %iused mounted on /dev/disk0s2 233gi 160gi 72gi 69% 42083619 18985821 69% / devfs 187ki 187ki 0bi 100% 648 0 100% /dev map -hosts 0bi 0bi 0bi 100% 0 0 100% /net map auto_home 0bi 0bi 0bi 100% 0 0 100% /home

python

No comments:

Post a Comment