On Sun, Apr 6, 2008 at 10:14 AM, Vineet Jain (gmail) <[EMAIL PROTECTED]> 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
[EMAIL PROTECTED]
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com