Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pickle- how does it work
#2
Don't use pickle,use Json is't just better and you get human readable file on disk.
Data serialization is the concept of converting structured data into a format that allows it to be shared,
or stored in such a way that its original structure to be recovered.

Instead of storing stuff in singe variables think of a data structure like eg dictionary.
>>> record = dict(name='jonathan', Damage=10)
>>> record
{'Damage': 10, 'name': 'jonathan'} 
import json

record = dict(name='jonathan', Damage=10)
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) #--> {'Damage': 10, 'name': 'jonathan'}
Reply


Messages In This Thread
pickle- how does it work - by foxtreat - Jun-19-2017, 09:16 AM
RE: pickle- how does it work - by snippsat - Jun-19-2017, 10:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 461 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  pickle problem DPaul 13 4,967 Sep-27-2022, 05:25 PM
Last Post: DPaul
  TypeError: cannot pickle n00sferatu 1 2,690 Dec-14-2021, 03:52 PM
Last Post: yakkaligiri
  Multiprocessing Can't pickle local object law 1 16,175 Aug-30-2021, 02:49 PM
Last Post: law
  Save/Loading using pickle Scordomaniac 4 3,085 Nov-24-2020, 06:11 PM
Last Post: Scordomaniac
  computing entropy using pickle files baran01 2 2,469 Dec-30-2019, 09:45 PM
Last Post: micseydel
  Tkinter don't get ver from file via pickle storzo 2 2,600 Jul-31-2019, 03:50 PM
Last Post: storzo
  pickle docs say bytes in one place, strings in another Skaperen 2 2,186 Jul-29-2019, 05:13 PM
Last Post: Skaperen
  pickle error SheeppOSU 4 11,033 Apr-20-2019, 04:50 PM
Last Post: SheeppOSU
  Using pickle.dump Friend 1 2,975 Feb-15-2019, 04:39 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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