An idiom for code generation with exec

Maric Michaud maric at
Tue Jun 24 01:44:57 EDT 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