[IronPython] Importing embedded .py files

JoeSox joesox at gmail.com
Tue Jul 4 07:09:34 CEST 2006


This is working except two of the embedded .py files import each
other, so no matter which one I place first, it errors out.  So I
guess I can catch it. lol. It's going to end up being about 60+ lines
of code to import 9 modules into the engine.
Or, I could modify the .py files some more but I prefer not to.


On 7/3/06, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
> As a workaround, you could create your own module objects very easily
> assuming you have the source code as a string.
>
> import imp
> import sys
>
> newModule = imp.new_module(moduleName)
> exec(sourceCode, newModule.__dict__)
> sys.modules[moduleName] = newModule
>
> You *should* then be able to import from this module in the normal way.
> (Unless I have made a mistake in the above code.)
>
> All the best,

-- 
Later, Joe



More information about the Ironpython-users mailing list