python中判断readline读到文件末尾

时间:2015-05-02 16:33:10   收藏:0   阅读:2603
fp = open(‘somefile.txt‘)

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

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

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!