Error using callback in Python

后端 未结 1 393
滥情空心
滥情空心 2021-01-17 16:05

I am developing a dll that should be used in Python. I have a callback function to send my parameters (defined in a separate header):

typedef int(*call_nBest)(

相关标签:
1条回答
  • 2021-01-17 16:32

    Do you want something like this?

    def callbackU(OutList, ConList, nB):
        for i in range(nB):
            print("{}\t{}".format(ConList[i], cast(OutList[i], c_char_p)))
        return 0
    

    From what I understand you're just trying to match the output of your Python callbackU function with your C++ MyCallback function.

    Python has a variety of string formatting functionality that can be confusing at first, but pays homage to printf string formatting.

    Since OutList has type LP_LP_c_char (pointer to pointer of c_char, vs "NULL terminated char *" c_char_p), we'd best turn it into a native Python data type like so:

    def callbackU(OutList, ConList, nB):
        for i in range(nB):
            out_list_item = cast(OutList[i], c_char_p).value
            print("{}\t{}".format(ConList[i], out_list_item))
        return 0
    
    0 讨论(0)
提交回复
热议问题