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

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 09:24:39

问题


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


回答1:


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.




回答2:


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.




回答3:


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




回答4:


Are you trying to run the program like this?

   /dirdir/MyPythonScript.py

try the following instead

   python /dirdir/MyPythonScript.py


来源:https://stackoverflow.com/questions/15121714/how-do-i-get-a-python-program-to-run-instead-of-opening-in-notepad

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!