Reusing a python filehandler?

前端 未结 2 1935
故里飘歌
故里飘歌 2021-01-25 02:39

I am a new to python and I need a help to understand the codes below -

def main():
    print(\'main\')

    fh = open(\'C:\\\\Python\\\\lines.txt\')
    for lin         


        
2条回答
  •  深忆病人
    2021-01-25 03:13

    Your file handle contains a position pointer. You can find out where you're at using fh.tell. It will move through the file for each line. Once you reach the end of the line, if you want to iterate through it again, you need to reset this pointer. fh.seek(0) would accomplish that for you.

提交回复
热议问题