Lets suppose I have a code in Python and in the middle of this code I have an eval
expression which depends on some external input, for example:
exp = raw_input()
eval(exp)
My question is: which mechanism Python's compiler and interpreter use to bind the code which can be compiled with the code that depends on a runtime value?
The Python compiler doesn't care where the code it's compiling comes from. It can compile code that comes from a file before execution when you run python filename
, it can compile files during execution when you use import
, and it can compile code from a string expression when you call eval()
or exec()
. These functions invoke the compiler dynamically.