使用Python 的 CFFI 库,我试图将 Python 字符串哄骗到 char* 中,以便我可以将它传递给接受 char* 的 C 函数。我似乎无法弄清楚正确的咒语是什么。
考虑这个例子:
>>> from cffi import FFI
>>> ffi = FFI()
>>> ffi.new("char[]", "bob")
结果是:
TypeError: initializer for ctype 'char[]' must be a bytes or list or tuple, not str
以下也不起作用:
>>> ffi.new("char*", "bob")
它说:
TypeError: initializer for ctype 'char' must be a bytes of length 1, not str