[IronPython] How to dynamically define and call a function?

Martin Maly Martin.Maly at microsoft.com
Mon Sep 18 17:24:48 CEST 2006

There is an extensive documentation on the hosting APIs that comes with the distribution (Doc\IronPythonApiReference.chm)

As for the example that didn't work for you ... you had 2 Python engines and the "testing" module was created in one of them whereas "import testing" was executed in different engine (the one controlled by the Python console).


-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Gary Stephenson
Sent: Monday, September 18, 2006 4:05 AM
To: Discussion of IronPython
Subject: Re: [IronPython] How to dynamically define and call a function?

d'oh!  I knew there must have been a straightforward way.

I'm still curious as to how to use the IronPython.Hosting stuff though, as I
thinkultimately it might prove to be more what I'm really after.



> 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)
> 5

users mailing list
users at lists.ironpython.com

More information about the Ironpython-users mailing list