G+_Ayesh Rodz Posted April 16, 2014 Share Posted April 16, 2014 Just to verify a small doubt, when I wrote a python script and later when I double click that ".py" file which I created, it's running like a ".exe". Just want to know is that because my pc has already installed python compiler or .py file type also acting/runs on windows platform just like an .exe without prior configurations to the system??? Link to comment Share on other sites More sharing options...
G+_Wesley Kerfoot Posted April 16, 2014 Share Posted April 16, 2014 It's getting executed by the python program running on your computer (which is an exe or what is called a binary executable). What happens is that python reads the file and translates it into its own internal language (called bytecode) and it executes that. This is done so that you can take a python program and run it on any computer that can run the python executable. If you were using a language like C or assembly you would likely have to change your program in various ways to get the same portability. Does that answer your question? Link to comment Share on other sites More sharing options...
G+_Darryl Medley Posted April 16, 2014 Share Posted April 16, 2014 Just like .doc files are "associated" with Word and .pdf files are associated with Acrobat Reader, .py files are associated with python.exe (or whatever version you have installed). Link to comment Share on other sites More sharing options...
G+_Lee Crocker Posted April 16, 2014 Share Posted April 16, 2014 Daryl has it right. The extensions ".py" and ".pyw" are associated with python.exe and pythonw.exe. When you click on the file, Windows runs the associated application with your file as input, which results in running the program. On the command line, you would have to type "python myscript.py" explicitly. (The extra w tells Windows to start the program in a window instead of a console). Linux and MacOS are different: If the first line of the .py starts with #!, that line itself tells the OS which program to run, and that will work even from the command line. And no extra w.? Link to comment Share on other sites More sharing options...
Recommended Posts