Dynamically defined functions via exec in imported module

Michele Simionato michele.simionato at gmail.com
Sat Aug 16 00:50:02 EDT 2008


On Aug 16, 4:48 am, Nadeem <nadeemabdulha... at gmail.com> wrote:
> I understand the 99% rule... the example I gave was to simplify the
> issue. The full thing I'm working on is a library for an introductory
> CS class I'm teaching. I'm trying, essentially, to build a library of
> macros for students to use allowing them to define records (like
> structs in C) with selector functions.

The namedtuple recipe by Raymond Hetting does
exactly that and, guess what, it uses exec!
Also the doctest module in the standard library
uses exec at good effect. So, I would say it is
not a 99% rule, let's say it is a 98% rule ;)
BTW, I also write a paper on namedtuple which I
am going to translate in English soon or later
(for the moment there is Google Translator):
http://stacktrace.it/articoli/2008/05/gestione-dei-record-python-1/
The paper, just as the namedtuple recipe,
has a strong functional bias so it may be of interest
to people coming from Scheme.

   Michele Simionato



More information about the Python-list mailing list