Skip to content

Instantly share code, notes, and snippets.

@laundmo
Last active March 28, 2020 21:31
Show Gist options
  • Save laundmo/830ed51437ed05cbf9df5ba3bff5fc30 to your computer and use it in GitHub Desktop.
Save laundmo/830ed51437ed05cbf9df5ba3bff5fc30 to your computer and use it in GitHub Desktop.
test for pickle

Testing whether pickling works with PySide2

spoiler: it does

from PySide2.QtWidgets import QGraphicsItem
import pickle
class Test(QGraphicsItem):
def __init__(self):
self.a = 1
def __setstate__(self, state):
self.a = state["a"]
def __getstate__(self):
return {"a":self.a}
t = Test()
pickle_string = pickle.dumps(t)
print("pickled")
b = pickle.loads(pickle_string)
print(b.a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment