Pickle weakref object

Viewed 75

I have a dictionary called Eggs:

Eggs = {}

I have a class called UserEgg:

class UserEgg:
    def __init__(self, user):
        self.warns = 0
        self.xp = 0
        self.user = user
        self.mute_time = 0
        self.records = []

    def InfoEmb(self):
        self.InfoEmbed = discord.Embed(title=f"{self.user} | User-info")
        self.InfoEmbed.set_thumbnail(url=self.user.avatar_url)
        self.InfoEmbed.add_field(name="Buttons:",
                                 value="⚠️: Warn user\n: Mute user\n: Kick user\n: Ban user\n: Open records\n❌: Close")
        return self.InfoEmbed

The Egg dict is supposed to contain an id (string) and an UserEgg object:

Eggs = {"122938192381923": UserEgg(0)}

I want to have a save() function to save this Egg dict to a file (preferably pickle)

This is what I have:

def save(Eggs):
    with open("user_data.pkl", "wb") as fp:
        pickle.dump(Eggs, fp)

When I use the save(Eggs) function now I get Cannot pickle weakref object

Is there any way to make it a non-weakref object or fix the error?

0 Answers
Related