Python Forum
Saving - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Saving (/thread-10813.html)

Pages: 1 2


Saving - Panda - Jun-07-2018

Is there a way to create a saving mechanism inside a python file?


RE: Saving - buran - Jun-07-2018

(Jun-07-2018, 06:36 PM)Panda Wrote: Is there a way to create a saving mechanism inside a python file?

What exactly do you mean by this? Please, elaborate


RE: Saving - Panda - Jun-08-2018

(Jun-07-2018, 07:00 PM)buran Wrote:
(Jun-07-2018, 06:36 PM)Panda Wrote: Is there a way to create a saving mechanism inside a python file?
What exactly do you mean by this? Please, elaborate
As in a separate file that has things like
start = True
completed = False
score = 10000



RE: Saving - buran - Jun-08-2018

You can save your code as py file. Is that what you ask?
check https://python-forum.io/Thread-Basic-How-to-Execute-python-code


RE: Saving - Panda - Jun-08-2018

(Jun-08-2018, 12:37 PM)buran Wrote: You can save your code as py file. Is that what you ask? check https://python-forum.io/Thread-Basic-How-to-Execute-python-code
I don't think so.
I would like a way to see how many times the program was started. No big deal, but that resets if it is in the file that is restarting. I would like a way to save it OUTSIDE of the file, so it can reach into the other file and get the EXACT number of times the program restarted.

Edit: I don't know if it matters which extension the file has, because it doesn't really matter to me.
Edit: As well as knowing the EXACT amount of times the program restarted, i want to store the amount of endings a player receives. Which means a TRUE or FALSE if the ending has already been found, and a number for the total of endings found.


RE: Saving - buran - Jun-08-2018

You can save/update whatever information you want in a separate file or in a database every time when the program runs.


RE: Saving - Panda - Jun-08-2018

(Jun-08-2018, 12:57 PM)buran Wrote: You can save/update whatever information you want in a separate file or in a database every time when the program runs.
but how
I know how to output to a file using logger, but i don't know how to get information from another file


RE: Saving - buran - Jun-08-2018

Did you check the documentation?
https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

or if you decide to use a sqlite DB
https://docs.python.org/3/library/sqlite3.html


RE: Saving - Panda - Jun-08-2018

(Jun-08-2018, 01:12 PM)buran Wrote: Did you check the documentation? https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files or if you decide to use a sqlite DB https://docs.python.org/3/library/sqlite3.html
I did. It didn't help enough.

The only thing i learned is
f = open('save_file', 'w')
writes to save_file.*, but i don't know how to write anything, or read it


RE: Saving - buran - Jun-08-2018

you are kidding, right?
https://docs.python.org/3/tutorial/inputoutput.html#methods-of-file-objects
and
https://docs.python.org/3/tutorial/inputoutput.html#saving-structured-data-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