Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
flpnhgajfz
1,858 Pointshow does python work?
To the best of my knowledge something like c, c#, c++, (and most languages) work by compiling the source code into machine instructions for the specific machine. The compiler runs makes the instructions and save them to a binary file. when you run that binary file (made of machine instructions) the operating system (kernel) budgets the instructions (along with other os instructions from the display, anti virus, clock, etc) and allows your compiled program to run. Python works a bit differently (to the best of my understanding) it translates your code into shell script (some how). So how does Python and the shell make the machine instructions? so is python saved as source code and distributed in ascli encoded source as opposed to binary(machine instructions)? Does the shell work any different form just a regular program execution?
1 Answer
Steven Parker
243,318 Points
Python is typically converted into bytecode which is then interpreted.
The conversion is generally an internal and transparent part of the process. The import thing is that the code gets interpreted. This means a running application (the Python program itself) examines the code and performs machine instructions internally based on what it sees. Python is not converted to shell script, and neither Python or shell script ever "make" machine instructions.
The Python program (and the shell) are both compiled programs and already have the machine instructions inside them needed to do whatever your script says to do.
I hope that clears things up a bit. Happy coding!
flpnhgajfz
1,858 Pointsflpnhgajfz
1,858 Pointsok so it translates to byte code (for deployment, storge, portability, etc) which is interpreted by a shell-like program? Basically like having csh and bash totally different shells?
thanks a ton for the response and same too you :)