Python Does Not Read Entire Text File

前端 未结 3 564
梦毁少年i
梦毁少年i 2020-12-31 07:05

I\'m running into a problem that I haven\'t seen anyone on StackOverflow encounter or even google for that matter.

My main goal is to be able to replace occurences o

3条回答
  •  梦谈多话
    2020-12-31 07:35

    Try:

    f = open("filename.txt", "rb")
    

    On Windows, rb means open file in binary mode. According to the docs, text mode vs. binary mode only has an impact on end-of-line characters. But (if I remember correctly) I believe opening files in text mode on Windows also does something with EOF (hex 1A).

    You can also specify the mode when using fileinput:

    fileinput.input("filename.txt", inplace=1, mode="rb")
    

提交回复
热议问题