[IronPython] Using IronPython with C#

Michael Foord fuzzyman at voidspace.org.uk
Sat Sep 5 00:32:16 CEST 2009


Alexander Baranosky wrote:
> Thank you Michael,
>
> I have seen the article you linked to.
>
> I now would like to know how to access the IronPython assemblies 
> (modules?) in PyScripter (remember I'm pretty new to Python).

The answer to that is 'it depends', and what it depends on most is how 
you organise your project. :-)

I would recommend IronPython in Action as giving you a good introduction 
to topics like this, but then I would wouldn't I...

PyScripter almost certainly doesn't have any specific support for 
IronPython so it won't 'recognise' *any* of the .NET things you use from 
IronPython (which is why I recommended the article on IronPython IDEs) 
but as a capable Python IDE you will still be able to use PyScripter for 
editing your Python code - you'll just need to use external tools to run 
them with IronPython.

Basically, to run a Python file with IronPython you run:

    > path\to\ipy.exe path\to\ipy_script.py

ipy.exe has references to the IronPython assemblies and so will use them 
automatically. Not *entirely* sure what you mean by " how to access the 
IronPython assemblies (modules?) in PyScripter".

> It doesn't immediately recognize the IronPython I try to import.  
> Also, how can I import assemblies from C# into an IronPython script?
>

To import from a C# assembly in IronPython the dll file must be 
contained in a directory on sys.path. You first need to add a reference 
to the assembly and then you can import from the namespaces it contains. 
Code like:

    import sys
    sys.path.append(r'C:\path\to\assemblies')

    import clr
    clr.AddReference('AssemblyName')

    import AssemblyName

Where the second AssemblyName is really a namespace. I hope that helps 
at least a bit...

All the best,

Michael Foord

> Thanks for the help,
> Alex
>
>
> > Alexander Baranosky wrote:
> > > I want to setup a project in .NET, using ironpython for unit testing
> > > and C# for writing the main project assemblies. I am not really a
> > > Python programmer, and am looking into the different IDE's. I like
> > > PyScripter so far but not sure how to use IronPython from it or how I
> > > can hook my Python tests up with my C# generated assemblies.
> >
> > I've not used PyScripter but it has a reputation as a good Python IDE.
> > My experience has been that I prefer working with Python IDEs for
> > IronPython than .NET IDEs as they have better features for working with
> > Python code (and IronPython code is just Python code after all).
> >
> > I did a write-up of several popular IDEs and their support for 
> IronPython:
> >
> > * http://www.voidspace.org.uk/ironpython/tools-and-ides.shtml
> >
> > IDEs covered:
> >
> > * IronPython Studio and Visual Studio
> > * SharpDevelop
> > * Wing
> > * Eclipse with PyDev
> > * Assorted other editors
> >
> > Plus it looks at some of the standard tools useful for developing with
> > Python and IronPython.
> >
> > HTH
> >
> > Michael
> >
> > >
> > > Any help is appreciated.
> > >
> > > All the Best,
> > > Alex
> > >
> > > 
> ------------------------------------------------------------------------
> > > With Windows Live, you can organize, edit, and share your photos.
> > > Click here. <http://www.windowslive.com/Desktop/PhotoGallery>
> > > 
> ------------------------------------------------------------------------
> > >
> > > _______________________________________________
> > > Users mailing list
> > > Users at lists.ironpython.com
> > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> > >
> >
> >
> > --
> > http://www.ironpythoninaction.com/
> >
> > _______________________________________________
> > Users mailing list
> > Users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
> ------------------------------------------------------------------------
> Hotmail® is up to 70% faster. Now good news travels really fast. Try 
> it now. 
> <http://windowslive.com/online/hotmail?ocid=PID23391::T:WLMTAGL:ON:WL:en-US:WM_HYGN_faster:082009> 
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog





More information about the Ironpython-users mailing list