for line in open(filename, 'rb'):
print(line)
这样写很美观,,很满意,,
但是我现在有个需求,,需要每次 print 128 个字节,,而不是一行,,这样的话就不得不用 read()来做,我想到的做法是:
file = open(filename, 'rb')
while True:
line = file.read(128)
if not line:
break
print(line)
file.close()
这样虽然能实现功能,,但感觉写法有点儿不 pythonic,不如上面的那个美观,,
请问调用 file.read()能不能做成上面那种遍历的形式??