1. 程式人生 > >Python 練習題:統計系統剩余內存

Python 練習題:統計系統剩余內存

ont 內存 split open spa pytho () utf clas

#!/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)

Python 練習題:統計系統剩余內存