1

First python file:-

class Person:
    def __init__(self, name, age):
        self.a = name
        self.b = age

    def show(self):
        print(self.a)
        print(self.b)


import pickle

Myob = Person()

with open('class.pickle', 'wb') as pick:
    pickle.dump(Myob, pick)

# with open('class.pickle', 'rb') as PickFile:
#     Get_dat = pickle.load(PickFile)
#
# Get_dat.show()

Second File:-

import pickle

with open('class.pickle', 'rb') as PickFile:
    Get_dat = pickle.load(PickFile)

Get_dat.show()

But if I put 2nd file code to 1st file it work correctly(now in comment)

Please help me

Dimuthu
  • 11
  • 3
  • You can check this and i hope this can answer your question :) https://stackoverflow.com/questions/10842553/pickle-with-custom-classes – Yusuf Syam Jul 16 '22 at 10:32

0 Answers0