When should I ever use file.read() or file.readlines()?

后端 未结 4 1562
天涯浪人
天涯浪人 2020-12-01 01:39

I noticed that if I iterate over a file that I opened, it is much faster to iterate over it without \"read\"-ing it.

i.e.

l = open(\'file\',\'r\')
         


        
4条回答
  •  死守一世寂寞
    2020-12-01 02:23

    Eesssketit

    That was a brilliant answer. / Something good to know is that wheneever you use the readline() function it reads a line..... and then it won't be able to read it again. You can return to the position by using the seek() function. to go back to the zero position simply type in f.seek(0).

    Similiarly, the function f.tell() will let you know at which position you are.

提交回复
热议问题