Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to save a class object to a file?
#1
i was using json to save some data for my game. While I was trying to save I noticed I got an error on serializing the Player class. I could save all the stats of the player, but that would be a hassle. Is there a way I can save the Player class to a file.
Age Doesn't Matter, Your Passion Does
- Shreya Jain
Quote
#2
Pickle or Shelve.

https://docs.python.org/3/library/pickle.html
https://docs.python.org/3/library/shelve.html

If it's just one object (the player), then Pickle. Shelve is sort of like a dictionary interface for using Pickle with a lot of different things.
metulburr likes this post
Quote
#3
It should be noted that pickling can be dangerous. If you are just using it for a local game, then you dont have to worry about anything.
micseydel likes this post
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  save content of table into file atlass218 3 103 6 hours ago
Last Post: ThomasL
  class returns NoneType Object istemihan 0 62 Aug-12-2019, 11:47 AM
Last Post: istemihan
  Object and type class Uchikago 2 128 Jul-28-2019, 10:35 AM
Last Post: DeaD_EyE
  Display output in readable format and save hnkrish 1 90 Jul-19-2019, 09:29 AM
Last Post: Larz60+
  How to save latest time stamp in a file? redwood 12 710 Jul-11-2019, 11:03 AM
Last Post: redwood
  Return a value when I equal an object from a class ihouses 4 194 Jul-10-2019, 02:44 AM
Last Post: SheeppOSU
  How can I save Python dictionaries in Matlab? jlostinco 1 208 Jul-04-2019, 11:35 PM
Last Post: scidam
  zip file variable prints <zipfile.ZipFile object at 0x7f83fd13bd90> ? Rsh 9 382 Jun-27-2019, 02:00 PM
Last Post: Rsh
  Save console output to text file (like a log) koticphreak 9 455 Jun-02-2019, 07:45 PM
Last Post: snippsat
  saving (in text or binary) an object under a defined class cai0824 3 310 May-12-2019, 08:55 AM
Last Post: snippsat

Forum Jump:


Users browsing this thread: 1 Guest(s)