I'm using Python 3.9 and I try to store an object with pickle. Although, this object contains an object list in which is contained another object list.
If I make the first object, store it using pickle, then delete it and retrieve it, without stoping the program, I have the list of the other object.
If I stop the program and then try to retrieve it, the list of the other object seems to be empty.
The class I've made looks like this:
class First():
list_of_Second = []
info = 0
def __init__(self,...,):
...
class Second():
list_of_Third = []
info = 0
...
class Third():
info = 0
...
def get_First_class_from_file(filename):
with open(filename, 'rb') as f:
return pickle.load(f)
So, when I try to retrieve my class from file, I get an empty list_of_Second. All the other info in the first class is retrieved.
Edit, partly solved thanks to @juanpa.arrivillaga:
I was using class-variables so it didn't work. If I put the list in the constructor, I will use an instance-variable and it will work for storing the list_of_Second. Although, the list_of_Third is empty again. The code looks like this:
class First():
info = 0
def __init__(self,...,):
list_of_Second = []
...
class Second():
info = 0
def __init__(self,...,):
list_of_Second = []
...
class Third():
info = 0
...
def get_First_class_from_file(filename):
with open(filename, 'rb') as f:
return pickle.load(f)