r/learnpython • • Mar 06 '15

Is python a machine level language?

I'm still learning high-level programming languages (currently C# & Ruby) but eventually want to move to something that is more directly involved with the actual processor & memory. I've seen alot of languages that claim to be compilation code & ever-so-powerful but still need a VM or some kind of translator to actually execute (COUGH COUGH JAVA). so id like to know, would python at all be considered compilation code?

0 Upvotes

18 comments sorted by

View all comments

1

u/Kerbobotat Mar 06 '15

Python is an interpreted language, at run time the code is translated to low level byte code (machine code) ad opposed to a compiled language, like c++ which is 'built' or compiled into a executable program. IIRC you can compile python using something like py2exe or Cython (compiles python to C) interpreted languages have more "steps" to execution, and can be significantly slower than compiled programs.

9

u/Rhomboid Mar 06 '15

Python's bytecode is very high level. It is nothing whatsoever like actual machine code. It executes on an abstract stack machine which has little in common with actual hardware, and its opcodes include things that perform very high level operations, like "get an attribute" or "import a module". A single one of these opcodes might require thousands (or millions) of actual machine instructions to implement.

Just because it's bytecode does not mean it's low level. Bytecode is really just a compact way of storing the result of parsing Python source code, and a technique for implementing an interpreter that has well-defined semantics and relatively good performance, all things considered.

1

u/Kerbobotat Mar 06 '15

Oh! Well then I've learned something new today as well! Thanks!

1

u/ivosaurus Mar 06 '15

Really you could say that bytecode is code that's stored as a binary representation (rather than text), or code meant specifically for a machine to read, rather than a human.

What there is to draw from these two hazy definitions is that neither of them mean that the actual code/representation need be low-level, or close to assembly instructions that a CPU would execute.

4

u/[deleted] Mar 06 '15

py2exe does not really compile the software. AFAIK it is just a packer, that extracts and runs a normal Python program.