[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Is there a way to use .NET DLL from Python

Huayang Xia

2/6/2008 9:27:00 PM

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
21 Answers

Shane Geiger

2/6/2008 9:37:00 PM

0

The following links *may* put you on the right path:


Calling DLL functions from Python (
http://aspn.activestate.com/ASPN/Cookbook/Python/Rec... ), a
fairly complete description with some helper class code. Another example
( http://aspn.activestate.com/ASPN/Cookbook/Python/Rec... ) of
using the calldll module to do this.

calldll module: http://www.nightmare.com/sof...


http://aspn.activestate.com/ASPN/Cookbook/Python/Rec...






Huayang Xia 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
>


--
Shane Geiger
IT Director
National Council on Economic Education
sgeiger@ncee.net | 402-438-8958 | http://ww...

Leading the Campaign for Economic and Financial Literacy

Luis M. González

2/6/2008 9:59:00 PM

0

On Feb 6, 6:27 pm, Huayang Xia <huayang....@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?

Luis

Huayang Xia

2/6/2008 10:26:00 PM

0

On Feb 6, 4:59 pm, "Luis M. González" <luis...@gmail.com> wrote:
> On Feb 6, 6:27 pm, Huayang Xia <huayang....@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?
>
> Luis

Is there anyway to import class (to generate objects) from .NET DLL?

Huayang Xia

2/6/2008 10:34:00 PM

0

Or maybe we can do it in IronPython?

Gabriel Genellina

2/6/2008 10:39:00 PM

0

Huayang Xia wrote:
>> I have several .NET DLL (I have no source code for them), is there
>> anyway to use them from python instead of from C#.

En Wed, 06 Feb 2008 19:37:02 -0200, Shane Geiger <sgeiger@ncee.net>
escribió:

> Calling DLL functions from Python
> (http://aspn.activestate.com/ASPN/Cookbook/Python/Rec... ), a
> fairly complete description with some helper class code. Another example
> ( http://aspn.activestate.com/ASPN/Cookbook/Python/Rec... ) of
> using the calldll module to do this.

Both recipes are rather obsolete now, since version 2.5 ctypes is included
in the standard library. Anyway they don't help the OP to load a .NET dll;
there is PythonDotNET http://pythonn... but I've never used it
myself.

--
Gabriel Genellina

Christian Heimes

2/6/2008 10:55:00 PM

0

Huayang Xia wrote:
> Is there anyway to import class (to generate objects) from .NET DLL?

You can use PythonDotNET if you want to access .NET assemblies in
CPython (the standard Python implementation written in C).

Christian

Fuzzyman

2/7/2008 12:16:00 AM

0

On Feb 6, 9:27 pm, Huayang Xia <huayang....@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

To access .NET types you either need to use IronPython or
Python.NET. .NET assemblies are dependent on the .NET runtime to do
anything and so can't be accessed with ctypes as other DLLs can.

Michael Foord
http://www.manning...

Fuzzyman

2/7/2008 12:17:00 AM

0

On Feb 6, 9:59 pm, "Luis M. González" <luis...@gmail.com> wrote:
> On Feb 6, 6:27 pm, Huayang Xia <huayang....@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 Foord
http://www.manning...

>
> Luis

Luis M. González

2/7/2008 2:26:00 AM

0

On 6 feb, 21:17, Fuzzyman <fuzzy...@gmail.com> wrote:
> On Feb 6, 9:59 pm, "Luis M. González" <luis...@gmail.com> wrote:
>
> > On Feb 6, 6:27 pm, Huayang Xia <huayang....@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...
>
>
>
> > 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

Fuzzyman

2/7/2008 8:53:00 AM

0



Luis M. González wrote:
> On 6 feb, 21:17, Fuzzyman <fuzzy...@gmail.com> wrote:
> > On Feb 6, 9:59 pm, "Luis M. Gonz?lez" <luis...@gmail.com> wrote:
> >
> > > On Feb 6, 6:27 pm, Huayang Xia <huayang....@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...
> >
> >
> >
> > > 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...