Skip to content

Instantly share code, notes, and snippets.

@manxisuo
Created June 4, 2015 14:11
Show Gist options
  • Save manxisuo/c30248f439f078e8cc53 to your computer and use it in GitHub Desktop.
Save manxisuo/c30248f439f078e8cc53 to your computer and use it in GitHub Desktop.
文件I/O
# 使用iter函数
with open('a.txt', 'r') as file:
for l in iter(file.readline, ''):
print(l)
# file对象是iterable
with open('a.txt', 'r') as file:
for l in file:
print(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment