Python 练习题:统计系统剩余内存

#!/usr/bin/env python
#-*- coding:utf-8 -*-

''' 统计系统内存信息 '''  

with open('/proc/meminfo') as fd:
    for line in fd:
        if line.startswith('MemTotal'):
            MemTotal = line.split()[1]
            continue
        if line.startswith('MemFree'):
            MemFree = line.split()[1]
            break
        
print "总内存:%sM" % (int(MemTotal)/1024)
print "剩余内存:%sM" % (int(MemFree)/1024)

 

 

 

 

 

    

posted @ 2019-01-11 15:55  孔雀东南飞  阅读(370)  评论(0编辑  收藏  举报