每天CookBook之Python-080

  • 固定大小记录的迭代
from functools import partial

RECORD_SIZE = 32

with open('somefile.txt', 'rb') as f:
    records = iter(partial(f.read, RECORD_SIZE), b'')
    for r in records:
        print(r)

out

b'Hello World'
posted @ 2016-07-24 12:56  4Thing  阅读(132)  评论(0编辑  收藏  举报