(Apr-01-2020, 05:25 PM)Rokafly Wrote: So the thing is I want to register informations in two lists. No problem for that but when I restart the program obviously this informations are gone.There are several ways,serialization is one way that can save and recovery original object structure
So my question is : how can I save this informations to use them in the following usage of my program?
So build in has Python has pickle and json.
Json is advisable to use.
So a example with two list could be saved like this.
import json # Your lists lst_1 = [1, 2 ,3] lst_2 = ['a', 'b', 'c'] # Make one list for easier saving record = [] record.append(lst_1) record.append(lst_2) with open("my_file.json", "w") as j: json.dump(record, j) with open("my_file.json") as j_out: saved_date = json.load(j_out) print(saved_date)
Output:[[1, 2, 3], ['a', 'b', 'c']]
# it's a fully working object
>>> saved_date
[[1, 2, 3], ['a', 'b', 'c']]
>>> saved_date[0]
[1, 2, 3]
>>> saved_date[1]
['a', 'b', 'c']
There are also easy to use small DB like TinyDB | dataset(my tutorial)sqlite3 come with Python.