[IronPython] Importing embedded .py files
Nathan R. Ernst
ernsnat at iit.edu
Tue Jul 4 00:12:46 PDT 2006
Out of curiosity, is there any sort of hook into the engine that would allow
you search for a module on your own? e.g. a search of sys.path did not find
the specified module, so before raising an import error, we give a set of
registered event handlers a crack at it? I would envision a cancelable event
would be raised, such that the first handler (if any) to successfully find
the module would prevent further handlers from being called.
I would need to take a closer look at the engine interfaces to see if this
would work, but I'd think this would be a relatively minor change (if its
not there already, of course).
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of JoeSox
Sent: Tuesday, July 04, 2006 12:10 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Importing embedded .py files
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,
users mailing list
users at lists.ironpython.com
More information about the users