python.net

Accessing System.Reflection.Pointer from python

这一生的挚爱 提交于 2019-12-09 06:53:25
I'm using pythonnet to access functions from a managed dll. One of the functions in the dll should return a float pointer (float*). When i call this function with pythonnet, it returns a System.Reflection.Pointer. Anyone an idea how I could get the actual data (an array of floats) from this pointer in python? Loading dll: import clr clr.AddReference(r"C:\Program Files\Thorlabs\Thorlabs OSA\ThorlabsOSAWrapper.dll") from ThorlabsOSAWrapper import * Calling function from dll: # x_values should be a float* but i get a System.Reflection.Pointer x_values = spectrum.GetXArray() 来源: https:/

How to pass python callback to c# function call

a 夏天 提交于 2019-12-09 00:44:02
问题 I am trying to use C# classes from python, using python.net on mono / ubuntu. So far I managed to do a simple function call with one argument work. What I am now trying to do is pass a python callback to the C# function call. I tried the following variations below, none worked. Can someone show how to make that work? // C# - testlib.cs class MC { public double method1(int n) { Console.WriteLine("Executing method1" ); /* .. */ } public double method2(Delegate f) { Console.WriteLine("Executing

Accessing System.Reflection.Pointer from python

China☆狼群 提交于 2019-12-08 06:35:42
问题 I'm using pythonnet to access functions from a managed dll. One of the functions in the dll should return a float pointer (float*). When i call this function with pythonnet, it returns a System.Reflection.Pointer. Anyone an idea how I could get the actual data (an array of floats) from this pointer in python? Loading dll: import clr clr.AddReference(r"C:\Program Files\Thorlabs\Thorlabs OSA\ThorlabsOSAWrapper.dll") from ThorlabsOSAWrapper import * Calling function from dll: # x_values should

ipython notebook & script difference - loading DLLs

随声附和 提交于 2019-12-08 06:33:54
问题 Did anyone notice the difference in loading .NET dlls between IPython/Jupyter notebook/(qt)console and normal python scripts using pythonnet? Is this a bug/behavior caused on pythonnet or ipython side? This works in ipython and python interactive console: import clr clr.AddReference(r"C:\path2dll\dotnetdll") But in regular python scripts, the sys.path has to be appended with the path to DLL: import clr import sys sys.path.append(r"C:\path2dll") clr.AddReference("dotnetdll") Possibly similar

How to cast a pointer to a Python cffi struct to System.IntPtr (.NET)?

折月煮酒 提交于 2019-12-08 06:33:21
问题 I need to pass a System.IntPtr to a .NET function (Python with pythonnet). This pointer should refer to a struct created in cffi. I found this: from CLR.System import IntPtr, Int32 i = Int32(32) p = IntPtr.op_Explicit(i) This is what I tried so far import clr from cffi import FFI ffi = FFI() custom_t = ''' typedef struct { float x; float y; float z; } float3; ''' ffi.cdef(custom_t) cfloat3 = ffi.new("float3 *") cfloat3.x = 1.0 cfloat3.y = 2.0 cfloat3.z = 3.0 print(cfloat3) from System import

How to embed properly using Python for .NET

*爱你&永不变心* 提交于 2019-12-08 05:04:41
问题 When I try to use PythonEngine.ImportModule(mymodulename) some of the optional modules in dependencies are attempted to be loaded (not required for module use without embedding). This results in return null from this method because some of these optional dependencies are not required and hence not available. What is the proper method to use in this PythonNET API for loading user-written module which depends on multiple other modules? 回答1: Looks like my issue was just importing the module

Python for .NET compilation for .NET3.5 and Python3.x

五迷三道 提交于 2019-12-07 18:54:31
Recently I've been working on a project which needs to use a .NET 3.5 Dll library, and the team is using Python3.x environment. So I went to the Python for .NET's github repo and downloaded the source code and tried compiling myself using Visual Studio 2013. In the source, there is a MVSC solution file named pythonnet , and I just opened the project and tried compiling Python.Runtime . By default, the Conditional compilation symbols is PYTHON27, UCS4 . So I changed it to PYTHON35, UCS2 to match my requirement. And I was able to compile it successfully. But since it needs to work with .NET

Passing bytes as parameter to c#?

纵饮孤独 提交于 2019-12-07 18:16:51
问题 I am currently stuck while trying to call a c# methods from python. I am using python 3.2 and not IronPython. I used pip to install the latest version of python.net Problem occurs (as often discussed) while using ref or out parameters. Here is my code so far: import clr path = clr.FindAssembly("USB_Adapter_Driver") clr.AddReference(path) from USB_Adapter_Driver import USB_Adapter gpio = USB_Adapter() version2 = '' status, version = gpio.version(version2) print ('status: ' + str(status)) print

How to embed properly using Python for .NET

痞子三分冷 提交于 2019-12-07 05:12:26
When I try to use PythonEngine.ImportModule(mymodulename) some of the optional modules in dependencies are attempted to be loaded (not required for module use without embedding). This results in return null from this method because some of these optional dependencies are not required and hence not available. What is the proper method to use in this PythonNET API for loading user-written module which depends on multiple other modules? Looks like my issue was just importing the module without extension (.py). Very stupid mistake, but hope this helps others who start with pythonnet. For one-file

How to unload a .NET assembly reference in IronPython

孤街醉人 提交于 2019-12-07 02:25:50
问题 After loading a reference to an assembly with something like: import clr clr.AddRferenceToFileAndPath(r'C:\foo.dll') How can I unload the assembly again? Why would anyone ever want to do this? Because I'm recompiling foo.dll and want to reload it, but the compiler is giving me a fuss, since IronPython is allready accessing foo.dll . 回答1: .NET itself doesn't support unloading just a single assembly. Instead, you need to unload a whole AppDomain . I don't know exactly how IronPython works with