Python 文件处理
2018-09-13 本文已影响0人
小淼不卖萌
Python 读文件处理
1. readline()
with open('file_name') as f:
while True:
line = f.readline()
if not line:
break
# do something
print line
pass
- with 处理开闭文件&文件异常处理
- readline()内部由生成器实现
- 返回空时跳出with