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
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 .
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!
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With