Dynamically defined functions via exec in imported module
Michele Simionato
michele.simionato at gmail.com
Sat Aug 16 10:04:57 EDT 2008
On Aug 16, 3:25 pm, George Sakkis <george.sak... at gmail.com> wrote:
> On Aug 16, 12:50 am, Michele Simionato <michele.simion... at gmail.com>
> wrote:
> > The namedtuple recipe by Raymond Hetting does
> > exactly that and, guess what, it uses exec!
>
> I might be wrong, but the reason namedtuple uses exec is performance.
> IIRC earlier versions of the recipe used a metaclass instead, so it's
> not that it *has* to use exec, it's just an optimization, totally
> justified in this case since namedtuples should be almost as fast as
> plain tuples.
I always thought the reason for "exec" was having a good signature in
the namedtuple constructor. I have not
measure performance, though.
More information about the Python-list
mailing list