How to change data in notepad using python [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
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. :)

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

Related

How to open and edit a file with .pas format which can be opened by Text editor or Notepad++ in Python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I would like to open a .pas file in Python, ( Generally, I can open the .pas by Text Editor to see what is inside). So, I am looking for the code to open and edit the file in Python.
To more clear, I would like to edit some variables in the file. So first I need to open it and then edit the file.
You can use the builtin open() function to open a text file:
with open('file.pas', mode='r') as f:
print(f.read())
Here are the docs

convert unknown file type readable by notepad to .csv files [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have 300 files with extension .EMA (never seen before) that I would like to convert to .csv files. The files are perfectly readable in Notepad. However, I need to convert them to .csv files as I want to read them with Python.
Does anyone know how to convert the files in a quick way?
Thanks.
The file extension doesn't determine the file contents. Both .csv and your file can be opened in notepad because they are text files. You don't have to do anything in this case - just use the file with .EMEA extension and it will work same thing as .csv
EDIT:
New information from comments seems to indicate the file is a csv-like file but using | as separator instead of the comma; if you're using pandas, try using
pd.read_csv('file.EMEA', delimiter='|')

Open a text file window using Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to write a text based game in python that uses a lexicon(A list of accepted inputs and their grammatical parts). Say I have a file lexicon.txt that contains a list of accepted terms for each room, such as attack(verb), dragon(noun), and up(direction). I know that I could print the contents of that file to my program with lexicon.read(), but then after the user has played enough that he can't see that part anymore, he might type an unrecognized word. I would rather have the lexicon constantly opened in another window where you could have easy access to it at any time. Is there any way to make my python file import lexicon.txt and open a window of notepad to display the contents?
There are many ways to do this.
This opens the file with the default application:
import os
os.startfile(filename)
To open the file explicitly with notepad use this:
import os
os.system("notepad.exe file.txt")

How do I call write a python function without opening the file beforehand? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm using python2.7, and have written a few functions for analyzing protein structure files, which I have saved as pdbtools.py One function, for example, is getprot() which lets me pull protein structures from a database.
After I open and edit the file and save it from python, I can then use all of the function definitions. However, when I start a new python session, it forgets all of my functions that I have written, so I have to %edit pdbtools.pdb, save it, and then I can run everything.
What's going on here? How do I use the functions that I have written?
If I understand right, you want open the interpreter and call the functions from that py script.
To doing so in python 2.7 you should do two thing, go in the directory where the .py file reside and save and empty text file named:
__init__.py
this tell the interpreter the files in that directory are good to import then use
import pdbtools
as the first thing you do opening a new interpreter, this import that file and all the function inside it, making them ready to use from the interpreter prompt

Python: How to make Next button read diffrent files. [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'am going to make a window with Next button, a Text Widget and Label widget. I want when I klick on Next button will read adiffrent files on Text widget, i mean first click on Nexst will read file_1 in Text widget, and secound click will read file_2, and so on. so can anyone help me, thanks
Shelf might do it. Try opening the file in shelf, reading it, printing it, then closing it. When the button is hit a variable is incriminated. This variable points to an index in an array which holds the file names. It would then pass the file path to the function like this:
import shelve
I = 0
Paths = array containing file paths
FUNCTION file (path):
This function opens reads prints and closes the - file at path
WHILE True:
This loop calls the function with args paths[i]
I++
BTW THAT EAS NOT MEANT TO BE PYTHON CODE BUT JUST A REPRESENTATION
P.S if I have got the wrong end of the stick pls tell me and I will change my awnser

Categories