[IronPython] Iron Python NewB questions . . .

Dino Viehland dinov at microsoft.com
Fri Oct 30 21:18:49 CET 2009


Frank wrote:
> So I've been reading the Iron Python docs plus installed and played
> with it a little bit . . . it doesn't look like Iron Python does
> quite what I need.
> 
> If I have a Python script . . . and I want to access a C# assembly .
> . . it looks like I am Golden.  (I have yet to actually get it to
> work, but it looks like the pieces are there.)
> 
> However, if I want to create a Python .NET assembly so I can call an
> existing Python class set from C# . . . it looks to me like that
> direction doesn't exist.

There's a couple of ways to do this.  You can define an interface or base
class on the C# side and implement it on the Python side.  Then you can 
cast the Python object to the interface or base class and use it that way.

Also w/ .NET 4.0 C# is getting the new static type "dynamic" which can
be used for interoperating with Python and other objects which respond
dynamically.  VB.NET, while already having dynamic support, also gets
updated so that it can consume IronPython and IronRuby objects.

> 
> The other thing that I see here, is that even if I adopt the "Python
> on top" philosophy . . . since I cannot create an assembly . . . I
> cannot create an executable file and I think also that things like
> Py2EXE and PyInstaller won't work either.
>
> That is . . . to run the resulting scripts, I have to install Iron
> Python on every target system.  (Currently we wrap our application
> using PyInstaller and so the customer does not have to have Python
> installed to run it.)

In the Tools\Scripts directory of the installation is a script called
pyc.py which can be used to compile Python code into a DLL or an EXE.
The resulting code still needs the IronPython libraries but it provides
a way to pre-compile the code (including down to native code using ngen)
and to not distribute the actual Python code.

> Lastly, I'm wondering is any of this is runnable under Unix Mono . .
> . I'm guessing the answer is "no".

IronPython does run on Mono under Unix.  Occasionally we break them but
the Mono team is usually pretty fast to respond to issues reported and
fix them.  I'm not sure what the current status is so you may need to
use the latest SVN for it to work.





More information about the Ironpython-users mailing list