Page 7 - BINARY FILE HANDLINNG
P. 7

A dictionary is written in a binary

          A tuple is written in a binary file                               file




           • t=((1,"anita",89),(2,"basant",6                                 • phone={"ankit":"5865698","ni

               7),(3,"kareena",56),(4,"tushar"                                   mish":"46445545","jitendra":"

               ,96))                                                             43434343"}

           • f=open("tuple.dat",'wb')                                        • f=open("dict.dat","ab")

           • pickle.dump(t,f)                                                • pickle.dump(phone,f)


           • print(‘Tuple written to file’)                                  • print("dictionary written")

           • f.close()                                                       • f.close()

                                                                             • f=open("dict.dat",'rb')


           • f=open("tuple.dat","rb")                                        • p=pickle.load(f)

           • tt=pickle.load(f)                                               • print(p)


           • print(tt)
   2   3   4   5   6   7   8   9   10   11