Jump to content

Just to verify a small doubt, when I wrote a python script and later when I double click that " ...


G+_Ayesh Rodz
 Share

Recommended Posts

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

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

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

 Share

×
×
  • Create New...