Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 15 Online
OpenStudy (anonymous):

First Q: What is the difference between .py and .pyw and .pyc file extensions? I'm newb so put it in the simplest way possible and I only care about the first two (You can discard .pyc) :) Second Q: when downloading python, it says (windows binary--doesn't include source) What does source here mean?? is it the source of the program itself or what? Thank u :)

OpenStudy (anonymous):

.py is the extension of Python Code file, pretty much like .cpp ,which generally run in by using Python Console, the dos window. .pyw is same, just it run without uisng Python Console, you generally use it to make GUI or no console apps. .pyc is the compiled version of above two, which contain the bytecode (the instructions which run in a virtual machine, much like assembly language) of your written code. This improves speed of code execution. When you download .msi setup which does not contain source code, it's not important if you don't want to modify/contribute/ or learn how python works. Source of program it itself but in form of written code, which is in c/c++ here. You can run program from source without compiling, as you do same.

OpenStudy (anonymous):

I don't really get the .pyc extension. Would you mind elaborating it a little bit? :) is it a python program but instead of being 'interpreted', it's 'compiled' (I'm 99.9% sure that I'm wrong :D )

OpenStudy (anonymous):

Ok,

OpenStudy (anonymous):

No, you're not wrong but also not right. When you run python code, then the virtual machine of python takes your code, converts it into byte code and then runs the "byte code". Here, the compilation of your code is done into the language for virtual machine, not your machine, called as byte code. Now when this byte codes is run, then virtual machine executes it in your machine converting byte code to machine code. We do this this because it'll be very slow to directly run the high-level code as it needs type checking, syntax checking, etc. where as byte codes is already verified for those things. So it makes processing very much faster. You can see example below. The python virtual machine is stack based. The byte code for def add(a,b): return a+b is like this - LOAD_FAST 0 (a) LOAD_FAST 1 (b) BINARY_ADD RETURN_VALUE The .pyc file contains this kind of code. Then when you run this file, the python directly runs this file in virtual machine as their is no need of compilation.

OpenStudy (anonymous):

I get it now. Thank you so much. :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!