Search code examples
pythonnotepad

How to change data in notepad using python


Ok so I want to make a simple game where it's essential for the game to save. I wish to store all the data in notepad. However how do I pull notepad into python. I have tried saving notepad into the same folder where my .py file is. Then in the program im not sure what to do. Im just very confused on how to do this. I do know how to program in python, but how do I pull data out of notepad into python.

Also I wish to know how would I change the inside of the notepad file. Let's just say it has a couple of variables with certain numbers. I want to change those in game.

Thank you for any answers. :)


Solution

  • You stored your data in text file not in notepad. Notepad is an application to edit and read the data inside the text file.

    Suppose you stored tha data in a text file (whose name is file.txt) using notepad. Now you want to read the data inside text file from your python code. You can read it directly as :

    Python code :

     file_pointer = open("file.txt", "r");
     array = file_pointer.readlines()
     print(array[0])
     print(array[1])
     print(array[2])
     print(array[3])
    

    file.txt

     25
     554
     51
     4147