7

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

FaerieDrgn
  • 305
  • 2
  • 3
  • 9

4 Answers4

9

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.

Oreo
  • 181
  • 1
  • 2
  • 12
3

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.

rn tmssn
  • 31
  • 3
1

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

bigblind
  • 12,539
  • 14
  • 68
  • 123
0

Are you trying to run the program like this?

   /dirdir/MyPythonScript.py

try the following instead

   python /dirdir/MyPythonScript.py