Files
Python_CookBook_repo/5.文件与IO/8.对固定大小的记录进行迭代.py
2025-09-10 16:12:45 +08:00

10 lines
403 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from functools import partial
if __name__ == '__main__':
RECORD_SIZE = 32
# partial函数主要起参数固定的作用接受一个函数和一组预设参数相当于给函数设置默认参数而不用修改函数
with open('5.文件与IO/4.bin_file.bin', 'rb') as f:
records = partial(f.read, RECORD_SIZE)
for record in records():
print(record, end='')