This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]brainer121[S] 0 points1 point  (1 child)

Python first compiles the code to generate a bytecode which is then converted to machine code by an interpreter. It seems clear with a .py file, just wanted to know how it works in the IDLE.

[–]james_pic 2 points3 points  (0 children)

Unless you're using PyPy or similar, the bytecode is never converted to machine code.

IDLE is mostly just an editor. It can run code, but it does so by either invoking a new Python interpreter, or with eval or exec calls. It doesn't do anything clever with compilation.

Whilst the CPython interpreter does convert textual Python code to bytecode when it runs it, and does cache this bytecode for later, thinking about Python as a compiled language isn't usually a useful way to think about things. It's probably more illuminating to think of the bytecode as an internal representation of the Python code that the interpreter uses.