简体   繁体   English

调用带有参数的 .Net 函数形式 python(通过引用传递)

[英]Calling a .Net function form python which takes an argument (passed by reference)

I am trying to invoke a .Net function from python using the Python.net module.我正在尝试使用 Python.net 模块从 python 调用 .Net 函数。 The existing code was written on Iron Python, I am in the process of converting the code base to Python 3.X version.现有代码是在 Iron Python 上编写的,我正在将代码库转换为 Python 3.X 版本。

Can somebody please help me with this?有人可以帮我解决这个问题吗? I am currently stuck at this point.我目前被困在这一点上。

The C# function: C# 函数:

public int waitforResult (out UInt32 Elapsed_time)

{
// Code snippet
}

IronPython code: IronPython 代码:

Elapsed_time = clr.Reference[System.UInt32](10000000) - (works fine in Iron Python)

Pyton.net code: Pyton.net 代码:

Elapsed_time = System.UInt32(10000000)

result = waitforResult(Elapsed_time)

It seems the wait time is not being considered似乎没有考虑等待时间

Thanks, Lipun谢谢,立邦

Python.NET bundles any out parameters with the return value into a tuple. Python.NET 将带有返回值的任何out参数捆绑到一个元组中。 So you need所以你需要

result, elapsed = waitforResult()

On a similar note, this is how you call Dictionary.TryGetValue :类似地,这就是您调用Dictionary.TryGetValue

found, value = dict.TryGetValue(key)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将参数传递给函数,该参数必须作为参数传递给python中的另一个函数 - Passing an argument to the function , which has to be passed as an argument to another function in python 如何读取作为参数传递给调用 function 的列表中的项目? - How to read an item in list which is passed as an argument to a calling function? Python C API:使用引用传递的参数调用Python函数 - Python C API: Call a Python function with argument(s) passed by reference 定义一个 python function 它需要 arguments 但也可以不带参数工作 - Define a python function which takes arguments but also works with no argument Python:函数需要给定2个参数中的1个 - Python: Function takes 1 argument for 2 given 仅将参数传递给 function 如果需要该参数 Python - Only pass an argument to a function if it takes that argument Python 调用函数作为参数传递而没有括号 - calling a function passed as an argument without parentheses 通过参数传递参数时在python中调用子进程 - Calling a subprocess in python when an argument is passed by parameter 对传递给函数 Python 的对象的引用 - Reference to object passed to function Python When calling a c function using ctypes.CDLL in Python, the function always gets 0 passed along as argument - When calling a c function using ctypes.CDLL in Python, the function always gets 0 passed along as argument
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM