Aug-08-2020, 07:40 PM
(This post was last modified: Aug-08-2020, 07:40 PM by Gribouillis.)
You want to serialize python objects, use the pickle module
>>> class MyClass: ... def test(self): ... print('Hello!') ... >>> obj = MyClass() >>> import pickle >>> s = pickle.dumps(obj) >>> s b'\x80\x03c__main__\nMyClass\nq\x00)\x81q\x01.' >>> obj2 = pickle.loads(s) >>> obj2.test() Hello!In this example pickle serializes a MyClass instance as a bytes object that can potentially be stored in a file and reused later.