[IronPython] Writing new modules

Nick Bastin nbastin at opnet.com
Mon Aug 16 19:47:07 CEST 2004

On Aug 16, 2004, at 1:14 PM, Jim Hugunin wrote:

> Nick Bastin wrote:
>> I'd like to take a hack at implementing _random, but I am a bit
>> confused as to how it works, so I have a few questions.  Keep in mind
> You should look at the existing modules such as math and re for some
> examples of how this can be done.  I believe this is a VERY simple 
> process.

Ok, just making sure it was as simple as it appeared.. :-)

>> It seems as if a module is available to the interpreter merely by
>> existing in IronPython.Modules.  Is this correct?
> This is mostly correct; however, the module also needs to be visible 
> to the
> interpreter, which for now probably means building it as part of
> IronPython.dll.  This is a configuration issue that will be resolved 
> moving
> forward.

That's fine, since that's technically how we build CPython as well.  
This actually generates another question - I don't have VC.NET, but 
rather am using Mono.  Is there any build system set up for non-VC 
builds, or do I have to make one?

>> sys.modules appears to be completely non-functional.  Is this a matter
>> of just not having an implementation, or is there a technical hurdle
>> here?
> I believe that sys.modules is only being used today for imports from 
> Python
> source code to avoid the circular import danger.  It's probably 
> completely
> non-functional for "builtin" modules.

It's functional for built-in modules, although hopefully built-in 
modules don't create the problem that it solves (C modules could still 
introduce a circular dependency, and it does solve that, but doing it 
in the standard distribution would be Bad(tm)).  It also allows for 
some rather nifty introspection by running programs to determine their 
environment (and allows you to solve the 'Reload everything that's been 
loaded since I started' problem).


More information about the Ironpython-users mailing list