Why can i read lines from file only one time?

后端 未结 4 1581
旧时难觅i
旧时难觅i 2020-12-07 01:42

I have a file containing python\'s object as string, then i open it and doing things like i showing:

>>> file = open(\'gods.txt\')
>>> file         


        
4条回答
  •  离开以前
    2020-12-07 02:49

    You can store the lines list in a variable and then access it whenever you want:

    file = open('gods.txt')
    # store the lines list in a variable
    lines = file.readlines()
    # then you can iterate the list whenever you want
    for line in lines:
      print line
    

提交回复
热议问题