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)