How to solve an EOF error when reading a binary file

后端 未结 2 665
耶瑟儿~
耶瑟儿~ 2021-01-22 03:39
class CarRecord:                    # declaring a class without other methods
  def init (self):                # constructor
    self .VehicleID = \"\"
    self.Registr         


        
相关标签:
2条回答
  • 2021-01-22 04:24

    what about this?

    while True:  # check for end of file
        try:
            Car.append(pickle.load(CarFile))  # append record from file to end of l i st
        except EOFError:
            print('EOF!!!')
            break
    
    0 讨论(0)
  • 2021-01-22 04:33

    you need to catch EOFError in your loop…

    You can't read forever from a file that does not contain infinite data, so you need to put a way for the loop to stop.

    Also, there is absolutely no need to have those loops, you can directly store the list, and it will just load the list.

    0 讨论(0)
提交回复
热议问题