Open fengyangfifa opened 6 years ago
from collections import namedtuple
Record = namedtuple('Record', ['kind','x','y'])
with open('data.p', 'rb') as f: records = (Record(*r) for r in read_records('<idd', f))
for r in records: print(r.kind, r.x, r.y)
这里应该把for循环写在with语句里面,否者会出现ValueError: read of closed file错误
from collections import namedtuple
Record = namedtuple('Record', ['kind','x','y'])
with open('data.p', 'rb') as f: records = (Record(*r) for r in read_records('<idd', f))
这里应该把for循环写在with语句里面,否者会出现ValueError: read of closed file错误