Page 6 - BINARY FILE HANDLINNG
P. 6

Steps for binary file processing







         To write data to a file                                              To read data from a file


        1.      Create a file using open ()                                  1. Open a file in ‘rb’ mode
                in binary access mode
                (‘wb’)                                                       2. Use load () method to

        2. Take input from user                                               de serialize object  from
                (usually in
                list,tuple,dictionary data                                          file object

                types)                                                       Syntax:
        3. Use dump() of pickle

                module                                                       object=pickle.load(file
                 to serialize the                                                   object)

              object(list/tuple/dictionary
              into byte stream)                                              3.    Process it

          • Syntax:
              pickle.dump(object,file
              object)
   1   2   3   4   5   6   7   8   9   10   11