An idiom for code generation with exec

Maric Michaud maric at aristote.info
Tue Jun 24 07:44:57 CEST 2008


Le Tuesday 24 June 2008 07:18:47 eliben, vous avez écrit :
> > If code generation is not the best, and I fail to see any performance
> > issue that could explain such a choice, except a misunderstanding of
> > what "compilation" means in python, just don't use it, use closures or
> > callable instances, there are many way to achieve this.
>
> And while we're on the topic of what compilation means in Python, I'm
> not sure I fully understand the difference between compiled (.pyc)
> code and exec-ed code. Is the exec-ed code turned to bytecode too,
> i.e. it will be as efficient as compile-d code ?

Yes, exactly the same, cpython always interprets compiled code, when a script 
is executed for example, it is parsed/compiled to bytecode by the interpreter 
before any execution. The .pyc/pyo files are just a cache created at import 
time to avoid the rather time consuming parsing stage.

-- 
_____________

Maric Michaud



More information about the Python-list mailing list