-2

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. :)

abc1234
  • 260
  • 3
  • 19
  • What do you mean by "store all the data in notepad"? Notepad is just a program; it doesn't store anything. – melpomene Jun 18 '16 at 00:46
  • Yes it actually does. If you save it, it can contain data which can be used later. – abc1234 Jun 18 '16 at 01:43
  • 1
    You save your text in text files. Notepad (the program) is not modified. You can read/write files in python directly. – melpomene Jun 18 '16 at 01:45

1 Answers1

3

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
Prince
  • 431
  • 3
  • 16
  • Is there any way I can edit the text through python, or should I just create a txt file using python and then edit it from there. – abc1234 Jun 18 '16 at 19:43
  • You [can read the file in, modify it programmatically in Python, and then write it back out again.](http://stackoverflow.com/questions/125703/how-do-i-modify-a-text-file-in-python) – rrauenza Jun 19 '16 at 05:54
  • Ok thank you I was kinda confused – abc1234 Jun 19 '16 at 19:28