[IronPython] How to dynamically define and call a function?
vagmi.mudumbai at gmail.com
Mon Sep 18 02:50:42 PDT 2006
Alternatively, you can simply use the file object to write it to a new
module and import it later.
newmod.write('def add(x,y):\n return x+y\n')
On 9/18/06, Sanghyeon Seo <sanxiyn at gmail.com> wrote:
> 2006/9/18, Gary Stephenson <garys at ihug.com.au>:
> > I started off trying to use standard "compile()" function and "exec"
> > statement, but was unable to make it work, although I'm sure there must
> be a
> > way. Is there? How?
> This works for me:
> IronPython 1.0.2449 on .NET 2.0.50727.42
> Copyright (c) Microsoft Corporation. All rights reserved.
> >>> code = "def add(x, y):\n\treturn x + y\n"
> >>> exec code
> >>> add(2, 3)
> Seo Sanghyeon
> users mailing list
> users at lists.ironpython.com
"Peace is its own reward." - Mahatma Gandhi
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the users