Re-open files in Python?

后端 未结 3 455
清酒与你
清酒与你 2020-12-01 13:50

Say I have this simple python script:

file = open(\'C:\\\\some_text.txt\')
print file.readlines()
print file.readlines()

When it is run, th

3条回答
  •  青春惊慌失措
    2020-12-01 14:20

    You can reset the file pointer by calling seek():

    file.seek(0)
    

    will do it. You need that line after your first readlines(). Note that file has to support random access for the above to work.

提交回复
热议问题