Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make save file configure in python

MY Tycoon game image

I have made a full game of tycoon but what i need for the game is that i want to save the player configure the money and the stores that still running with this code i use pycharm and python 3.9.
Also i use tkinter gui for it and have been 5 project so please help <‘_’>

I have try my idea which the player could load from the txt file and save the txt file btw the txt file is a code that lead to the program and make changes.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use:

text = 'Your text'
with open('save.txt', 'w') as file:
    file.write(text)

This will cause the ‘save.txt’ file to be completely overwritten with ‘Your text’.

If you want to read the text that is written in the file you would have to use:

with open('save.txt', 'r') as file:
    text = file.read()

You could implement it like this:

save_file = '<your save file path>'
with open(save_file, 'r') as file:
    text = file.read()

# game code

text = '<str that will be saved inside of save_file>'
with open(save_file, 'w') as file:
    file.write(text)

You can find other solutions to this problem here: How to create a new text file using Python

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading