ActiveState ActivePython
ActiveState's ActivePython is the
industry-standard Python distribution available for Windows, Linux, Mac
OS X, Solaris, AIX and HP-UX. Currently it is not providing default support for
execution or calling .Net modules which is similar to the behavior of CPython.
But ActivePython has support for calling win32 APIs from win32 dlls using
pywin32 module.
Python for .Net
Python for .NET is a package that
gives Python programmers nearly seamless integration with the .NET Common
Language Runtime (CLR) and provides a powerful application scripting tool for
.NET developers.Python.Net binaries available for download in https://github.com/geographika/PythonDotNet
Adding .Net support in ActivePython
We
can add support for .Net modules in ActivePython by installing python.Net in
ActivePython folder.
Installing Python.Net into ActivePython
ActivePython root
folder is the folder where Active python is installed (Usually active python
installed in C:\Python27 folder). Python.Net binary files are Python.Runtime.dll,
Python.Runtime.pdb and clr.pyd.
Follow the below
steps to install python.net in active python.
- Download Python.net binaries from https://github.com/geographika/PythonDotNet. Make sure that you download the binaries compatible with ActivePython( 32 bit or 64 bit)
- Copy all the downloaded binary files to the folder rootfolder\DLLs (For E.g., C:\Pyhton27\DLLs)
Examples
- · How to add reference to the .Net assemblies from python.net
Import
clr
clr.AddReference
("System.Windows.Forms")
from
System.Windows.Forms import MessageBox
MessageBox.Show
("hi")
- · How to call a function which has out parameter
o
I have function in C# named GetEmployeeName in Employee class which has the below
function definition.
string GetEmployeeName (string id, out string errorMessage)
Here the function returns the name of the employee if we provide the
unique id of the employee. If there is any error when retrieving the value, out
parameter errormessage will hold the error message.
From python.net we can call this function as below
import clr
clr.AddReference(“EmployeeDB”)
import Employee
error=””
emp = Employee()
(empId, error)= emp .GetEmployeeName (“101”, error)
print empId
print
error
No comments:
Post a Comment