TypeError: item 2 in _argtypes_ passes a union by value, which is unsupported.
时间: 2024-03-23 12:42:04 浏览: 40
这个错误通常是由于 ctypes 库在调用某个函数时无法处理 C 语言中的 union 类型所导致的。这种情况下,可以尝试使用 `ctypes.wintypes` 中定义的 `LP_` 类型来代替 union 类型,例如:
```python
from ctypes import *
from ctypes.wintypes import *
# 定义输入参数类型
class INPUT(Structure):
_fields_ = [
("type", c_ulong),
("ki", c_uint * 3)
]
# 构造输入参数
input = INPUT()
input.type = INPUT_KEYBOARD
input.ki[0] = VK_CAPITAL
# 调用 SendInput 函数
SendInput(1, byref(input), sizeof(INPUT))
```
这里我们使用了 `c_uint * 3` 来代替原来的 union 类型,这样就可以避免 `TypeError` 错误了。如果你遇到了其他问题,可以贴出详细的代码和错误信息,我可以帮你进一步调试。
相关问题
运行app = Application().start("D:\WeChat\WeChat.exe")时出现TypeError: item 2 in _argtypes_ passes a union by value, which is unsupported.
这个错误通常是由于 ctypes 库在调用某个函数时无法处理 C 语言中的 union 类型所导致的。这种情况下,可以尝试使用 `ctypes.wintypes` 中定义的 `LP_` 类型来代替 union 类型,例如:
```python
from ctypes import *
from ctypes.wintypes import *
# 定义输入参数类型
class INPUT(Structure):
_fields_ = [
("type", c_ulong),
("ki", c_uint * 3)
]
# 构造输入参数
input = INPUT()
input.type = INPUT_KEYBOARD
input.ki[0] = VK_CAPITAL
# 调用 SendInput 函数
SendInput(1, byref(input), sizeof(INPUT))
```
这里我们使用了 `c_uint * 3` 来代替原来的 union 类型,这样就可以避免 `TypeError` 错误了。如果你遇到了其他问题,可以贴出详细的代码和错误信息,我可以帮你进一步调试。
TypeError: L2.__init__() got an unexpected keyword argument 'l'
这个错误通常发生在使用Python中的类的构造函数时,当你给构造函数传入了一个它并不接受的参数时会出现这个错误。例如,在类L2的构造函数__init__中没有定义参数l,但是你却给它传入了一个参数l,这样就会出现TypeError: L2.__init__() got an unexpected keyword argument 'l'的错误。
解决这个错误的方法是要检查你的代码,找出在哪里使用了构造函数并传入了一个不被接受的参数。如果是无意之间传入了一个错误的参数,你可以删除这个参数。如果你确实需要使用这个参数,则需要在类的构造函数中添加该参数的定义。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)