嵌入 Python:如何帮助脚本编写者?
我正在使用 Boost 将 Python 嵌入到我的应用程序中。例如,我想检查以下函数是否接收一个整数和一个字符串作为第一个和第二个参数(该函数是在 C++ 中定义的)。
someFunction(123, 'words')
例如,如果我发现参数不正确,我如何通知脚本编写者需要更正哪一行?
I'm using Boost to embed Python in my application. For example, I want to check that the following function receives an integer and a string as the first and second parameters (the function is defined in C++).
someFunction(123, 'words')
If I find that the parameters are incorrect, how can I notify the scripter about which line they need to correct, for example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用通常的
def("someFunction",someFunction,...)
包装函数,调用者将自动收到有关 C++ 签名的通知,该签名无法与传递的对象匹配来自 python,如下所示(该方法采用一个字典参数,而是用 3 个数字调用):您可以发布一些代码来看看您的问题是什么吗?
If you wrap the function using usual
def("someFunction",someFunction,...)
, caller will get automatically notified about c++ signature which could not be matched with objects passed from python, like this (the method takes one dictionary argument, is called with 3 numbers instead):Can you post some code to see what is your problem?
使用您希望他们了解的所有信息引发异常,就像在 Python 中一样。事实上,这个答案似乎很明显,这让我觉得我在你的问题中遗漏了一些东西。
Raise an exception with all the information you want them to know, just like you would in Python. In fact, that answer seems so obvious, it makes me think I'm missing something in your question.