Creating function object from text
George Yoshida
ml at dynkin.com
Sun Apr 18 00:39:02 EDT 2004
Edward C. Jones wrote:
> Suppose I have a piece of text that defines a function:
>
> text ="""\
> def fun(i):
> return i + 2
> """
>
> How do I turn this into a function object, f, which can be called or
> passed around?
Aside from Peter's advice, I'd recommend you to look into timeit.py and
doctest.py.
These two library is a good example of how to use exec and compile in a
real application.
--
George
More information about the Python-list
mailing list