[IronPython] Trying to use the library preppy from reportlib in ironpython and silverlight

Curt Hagenlocher curt at hagenlocher.org
Sun Apr 6 19:49:03 CEST 2008

On Sun, Apr 6, 2008 at 10:14 AM, Vineet Jain (gmail) <vinjvinj at gmail.com> wrote:
> But that is not the problem. If I have the following string
> python_source = """
> def function test_dynamic():
>        return 1
> """
> How do I load this function at run time and be able to call the function
> Some_module.test_dynamic()?

Here's an example that may help you:

import imp
import sys

python_source = """
def test_dynamic():
    return 1

module = imp.new_module('some_module')
sys.modules['some_module'] = module
exec python_source in module.__dict__
from some_module import test_dynamic
print test_dynamic()

You can "exec" a string against any dictionary; you don't actually
need a module to do it.

Curt Hagenlocher
curt at hagenlocher.org

More information about the Ironpython-users mailing list