Is it possible to store Python class objects in SQLite?

后端 未结 9 2034
独厮守ぢ
独厮守ぢ 2020-12-22 17:42

I would like to store Python objects into a SQLite database. Is that possible?

If so what would be some links / examples for it?

9条回答
  •  情话喂你
    2020-12-22 18:08

    You can use pickle.dumps, its return pickable objects as strings, you would not need to write it to temporary files.

    Return the pickled representation of the object as a string, instead of writing it to a file.

    import pickle
    
    class Foo:
        attr = 'a class attr'
    
    picklestring = pickle.dumps(Foo)
    

提交回复
热议问题