r/pythonhelp • • Dec 02 '22

question about how to store a solution

I'm currently in a class for python and for our final we have to make a program that uses the things we've learned. But how I want to use dict/pickle we haven't been taught or isn't in the book we use, and I cant find the answer to my question online.

My program is a menu based calculator and I want to store my solutions to look up later via a list, Do I just store the object of the equation and it brings the result with it, or is there a way to just store what it creates as a value.

As a base I have you input say an x value and a y value they become self.x/y respectfully, do I save that or how do I save just the end result from something like self.x ** self.y.

0 Upvotes

6 comments sorted by

1

u/Goobyalus Dec 03 '22

Can you clarify what you want to store, with examples?

1

u/[deleted] Dec 03 '22

X × Y = Z. X and Y are inputs, I want to save Z.

1

u/Goobyalus Dec 03 '22

The tems are "serialization" and "deserialization".

You can serialize whatever object you want with pickle (but it won't be portable). You can save a number as text, and parse that text back out as a simple form od serialization. You can use JSON, but it doesn't distinguish between ints and floats. You could use any number of srialization schemes.

Dict isn't a serialization, it's a data type. You could serialize and deserialize a dict.

1

u/[deleted] Dec 03 '22

Ok, I'll try that, thank you

1

u/SDG2008 Dec 03 '22

You mean like make Jason file?

1

u/[deleted] Dec 03 '22

I'm sorry but I dont know what that is, hes requires us to use pickle for our dictionary work.