[IronPython] How to dynamically define and call a function?
sanxiyn at gmail.com
Mon Sep 18 11:36:26 CEST 2006
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)
More information about the Ironpython-users