Is there a way to use .NET DLL from Python

Fuzzyman fuzzyman at gmail.com
Thu Feb 7 09:52:34 CET 2008



Luis M. González wrote:
> On 6 feb, 21:17, Fuzzyman <fuzzy... at gmail.com> wrote:
> > On Feb 6, 9:59 pm, "Luis M. Gonz�lez" <luis... at gmail.com> wrote:
> >
> > > On Feb 6, 6:27 pm, Huayang Xia <huayang.... at gmail.com> wrote:
> >
> > > > Hello All,
> >
> > > > I have several .NET DLL (I have no source code for them), is there
> > > > anyway to use them from python instead of from C#.
> >
> > > > Thanks,
> > > > Huayang
> >
> > > I used to put my .dll files into the .DLL folder, so I could simply
> > > import them as I would with any other python module.
> > > But since I started using Ironpython 2.0 Alpha* this doesn't work
> > > anymore...
> > > Any hint?
> >
> > The rule is probably still that the DLLs must be in a directory on
> > sys.path for the interpreter to find them. Try adding the directory
> > containing the assemblies to sys.path and see if you can add
> > references to them.
> >
> > Michael Foordhttp://www.manning.com/foord
> >
> >
> >
> > > Luis
>
> I tried adding the directory to sys.path.
> Still not working...
>
> >>> import sys
> >>> sys.path.append('C:\Documents and Settings\luismg\Escritorio\IronPython-2.0A
> 8\DLLs')
> >>> from ClassLibrary1 import *
> Traceback (most recent call last):
>   File , line unknown, in ##235
>   File , line unknown, in _stub_##2
> ImportError: No module named ClassLibrary1

You need to add references to assemblies before you can import from
the namespaces they contain.

import clr
clr.AddReference('ClassLibrary1')

HTH

Fuzzyman
http://www.manning.com/foord




More information about the Python-list mailing list