我总是用Python读取文件:
for line in open('filename'):
pass
最近,python开始喷出这个警告:
ResourceWarning: unclosed file <_io.TextIOWrapper name='filename' mode='r' encoding='UTF-8'>
如果没有这种警告,什么是pythonic方式读取文件中的每一行?
with open('filename') as f:
for line in f:
pass
感觉像线条(和缩进级别)太多。