Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving results
#2
(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.
So my question is : how can I save this informations to use them in the following usage of my program?
There are several ways,serialization is one way that can save and recovery original object structure
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.
Reply


Messages In This Thread
Saving results - by Rokafly - Apr-01-2020, 05:25 PM
RE: Saving results - by snippsat - Apr-01-2020, 06:09 PM
RE: Saving results - by Rokafly - Apr-03-2020, 01:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 2,358 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  How to append one function1 results to function2 results SriRajesh 5 3,345 Jan-02-2020, 12:11 PM
Last Post: Killertjuh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020