from collections import namedtuple Disk = namedtuple('Disk', 'a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14') def get_disk_info(device): with open('diskstats') as f: for line in f: line = line.split() if line[2] == device: return Disk(*(line)) raise RuntimeError('device {} not found!'.format(device)) def main(): disk_info = get_disk_info('sda1') print(disk_info) print('磁盘写次数:{}'.format(disk_info.a8)) if __name__ == '__main__': main()