Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a python program to run instead of opening in Notepad?

Tags:

python

notepad

I am having some trouble with opening a .py file. I have a program that calls this .py file (i.e. pathname/example.py file.txt), but instead of running the python program, it opens it in Notepad. How to I get it to run?

The program itself takes in a file, and creates an output that is more readable.

Edit: The operating system is Windows 7. And the file that is calling the python is a .bat file.

Edit 2: It looks like I had to reinstall python for some reason... but it looks like it is finally working. Why reinstalling never comes to mind in the first place... And then I had to change how the file extention was opened. Thanks guys

like image 490
FaerieDrgn Avatar asked Feb 27 '13 20:02

FaerieDrgn


People also ask

How do I change the default file opener for Python?

Right-click on any Python file. Select Properties . Next to the section that says “Opens with”, click the Change button. You may need to select More Apps .

How do I run a .py file directly?

To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World! If everything works okay, after you press Enter , you'll see the phrase Hello World!

Can I run python code in notepad?

By using Notepad and the Python interpreter, a programmer can write Python programs and execute them, or create "batch" files that can execute multiple programs, including Python scripts.


3 Answers

This happened because most probably you have set notepad as the default program to open a .py file. Go to default programs app in windows. Select choose app by extension. Here search for .py files. Change the option from notepad to python. This should solve your problem.

like image 54
Oreo Avatar answered Oct 27 '22 06:10

Oreo


okay.
1) i tried turning it off and on again. 2) i uninstalled and reinstalled python

still no joy. and then!

in windows explorer there's an open with option that sets the default program that windows is pointed toward if you click on the filename or enter it on the command line. change that from notepad or whatever it is if it's not python. change it to python. then presto. no problem-o.

like image 22
rn tmssn Avatar answered Oct 27 '22 06:10

rn tmssn


You need to run it from the command line. http://docs.python.org/2/faq/windows.html#how-do-i-run-a-python-program-under-windows

like image 32
bigblind Avatar answered Oct 27 '22 06:10

bigblind