HelloWorld HelloWorld - 1 year ago 63
Python Question

Does a python code with the function exec in it get compiled to an executable?

I am new to python and I have never compiled python code to an executable file before. The languages I am well familiar with are C, C++, and Java and I have never come across a language that lets you modify the code from within itself, like Python which uses has the method


For the following code,

a = 500
code = raw_input()
exec (code)

When I give the input as,
print (a)
the program displays the value in
. So this means the variable
comes within the scope of the code

I don't understand what would happen if we try to convert the python code to an executable using a program like
. Will the method
still work? If it does work, does
bring the entire Python compiler and interpreter with it when the program gets compiled?

Answer Source

py2exe never compiles Python code into native executables; it bundles up a Python interpreter into an executable, always. This is likewise true of freeze, cx_Freeze and every other tool offering similar functionality while supporting the full Python language rather than a limited subset thereof.

Thus, exec, eval and similar constructs are available without needing additional facilities.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download