python中判断readline读到文件末尾

fp = open(‘somefile.txt‘)

while True:
     line = fp.readline() 
     if not line:
        break

Python中,空串的not返回true,即not line时为读到EOF(文件末尾)

文章来自:http://www.cnblogs.com/summerkiki/p/4472043.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3