I am porting a CSharp app to python and have the line:
string sBlockName = GetInfo(iBlockID, out dLength, out dWidth);
Where
iBlockID is passed to the function
sBlockName is the return value
dLength and dWidth are passed by reference using the out keyword.
How to write this in python?
Any help is appreciated!
Please note that I don’t want to rewrite this function in Python since it is a library function and I only want to translate the above single line to Python.
I don’t know that we have enough information to say much. Python uses pass my reference for complex data types, so I wouldn’t expect a problem. What have you tried? In which ways has it failed?
You can imagine that the function looks up a database of Blocks that has columns like
Block_ID, Block_Name, Block_Length, and Block_Width.
So the function GetInfo Takes the ID and returns the Name of the block and also the length and the width of the block for the given ID.
I don’t know what’s inside the function.
It is a library function.
string sBlockName = GetInfo(iBlockID, out dLength, out dWidth);
I can use it in CSharp and it returns the block’s name sBlockName when I provide the block’s ID in BlockID.
Besides that, it also fetches the block’s length and width in the out variables dLength and dWidth.
As mentioned earlier in the main question, I do not want to re-write the function, I only want to write the equivalent line of code for the CSharp function call:
string sBlockName = GetInfo(iBlockID, out dLength, out dWidth);
So you are writing a Python wrapper around existing CSharp code? You need to look into ffi. I know how to do this for C, but I’d have to Google extensively to do it with CSharp .
Do you have some reason to suppose that just calling the CSharp function in Python with a different number of arguments should work? How is that function represented in Python? You can’t just call a CSharp function from Python without some serious legwork.
Without knowing much, much more, I have no way of telling what is going on.
But I thought you were calling to a CSharp library for this function?
I’m so confused.
You need a way to replicate the action of this function. You can do this by either rewriting the function in Python or by calling the CSharp function from Python. Which do you want to do?
The library was perhaps written in C, I have no clue.
It is a DLL file and contains the function GetInfo.
It is a third-party library and I don’t have the source code.
Hence I cannot rewrite the function as I don’t know what happens inside the function.
Previously, I was using CSharp to write an app that calls this GetInfo function and it worked well.
Now the client wants to write another app in Python that also uses the same DLL library and the function GetInfo from that library.
I want to use that function from that DLL library in Python.
There are hundreds of other functions in that library that I can call in Python without issues.
Only this function GetInfo is not working properly.
I gave the CSharp syntax to provide information on how that function works in CSharp and its definition.
string sBlockName = GetInfo(iBlockID, out dLength, out dWidth);
Now, I want to write a Python equivalent of the above line.