python - pybind11:从 c/c++ 获取 python 函数的参数数量
问题描述
在 pybind11 中,我有一个类型为 的变量pybind11::function
。在 c++ 中,有什么方法可以确定该函数需要多少个参数?即,如果它来自def f(a, b)
,答案将是 2。我意识到这可能会变得疯狂 w/r *arks、kwargs、self 等......
需要明确的是,这是在 c++ 内部,所以我正在寻找 c++ 代码。
解决方案
这是您可以使用的方法inspect.signature()
:
from inspect import signature
import os # I only imported os to demonstrate with one of its functions
print(signature(os.remove)) # Print out the arguments for the remove fumction from the os module
输出:
(path, *, dir_fd=None)
推荐阅读
- asp.net-mvc - 如何在没有页面刷新或重定向的情况下在 ASP.NET MVC 中进行文件上传
- php - 在 wordpress 主题中设置的每个类别一篇文章(tagdiv 作曲家)
- git - 如何使用终端访问 Git 用户手册[1]?
- python - 测试 numpy 数组是否是 numpy 数组列表的成员,并将其从列表中删除
- mongodb - MongoDB 中的 MapReduce 不会一次性减少所有具有相同键的 kv 对
- jsonpath - 如何获取过滤的 JSONPath 输出的第一个值
- android - fontFamily 在低于 24 的 API 级别上无法按预期工作
- java - 我如何访问我们在 Ionic Projects 中获得的 MainActivity 中的应用程序
- reactjs - 增加打字稿中的反应类型的问题
- mongodb - ReactiveMongo 可以在 Lagom 框架中使用吗?