Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving
#11
(Jun-08-2018, 02:05 PM)buran Wrote: you are kidding, right? https://docs.python.org/3/tutorial/input...le-objects and https://docs.python.org/3/tutorial/input...-with-json if you want to use json (better, because you get structured data) there are numerous examples how to read and write to file
Believe me, the sooner you learn to use the docs, the better
Can i just get a straight answer? I followed EXACTLY what the document said and got an error.

I tried something different and got an error:
import pickle
control = True
control = Control(...)
with open('savefile.dat', 'wb') as f:
    pickle.dump([control], f, protocol=2)
And got the error
Error:
Control is not defined
So i changed the code to this
import pickle
control = True
control = control(...)
with open('savefile.dat', 'wb') as f:
    pickle.dump([control], f, protocol=2)
And got the error
Error:
'bool' object is not callable
Self-taught HTML, CSS, Python, and Java programmer
Reply
#12
Edited. I see someone recommended pickle

Try removing the brackets from control
Reply
#13
Now it inputs
Output:
€]q ^a
But only in Windows 1252 encoding
Self-taught HTML, CSS, Python, and Java programmer
Reply
#14
Try this example
Reply
#15
(Jun-24-2018, 01:02 AM)Grok_It Wrote: Try this example

Thank you. This worked
Self-taught HTML, CSS, Python, and Java programmer
Reply
#16
(Jun-24-2018, 01:18 PM)Panda Wrote:
(Jun-24-2018, 01:02 AM)Grok_It Wrote: Try this example

Thank you. This worked

Awesome, glad to hear it.
Watch out keeping pickles too long. If you change the structure of the object after pickling, you may not be able to unpickle old copies. To defeat this I've added version numbers as class variables. Then each time I change the object I save the old version in a helper module that unpacks the old version into its correct class and upgrades it.
Reply


Forum Jump:

User Panel Messages

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