Skip to content

Instantly share code, notes, and snippets.

@KuKuXia
Created December 28, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KuKuXia/1b9c92f367d39ca04fa2842d3287c9f3 to your computer and use it in GitHub Desktop.
Save KuKuXia/1b9c92f367d39ca04fa2842d3287c9f3 to your computer and use it in GitHub Desktop.
利用迭代器实现数据的块输入
"""
利用迭代器实现数据的块输入
"""
CHUNK_SIZE = 50
with open('somefile.txt') as f:
for chunk in iter(lambda: f.read(CHUNK_SIZE), ''):
print(chunk)
print('-' * 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment