对于def foo(),PyRun_SimpleString失败:
PyRun_SimpleString fails for def foo():
对于名称/路径中包含unicode(widechar)的文件,我无法使PyRun_SimpleFile正常工作(FILE*兼容性问题),因此出现此问题!
所以,我决定自己打开python脚本&然后使用PyRun_SimpleString执行每一行。
此处显示的伪代码。
wchar_t* pWScriptName=NULL;
// pWScriptName malloced & populated here
FILE* fp = _wfopen(pWScriptName, L"r");
while (fgets(line, BUFSIZ, fp) != NULL) {
int ret = PyRun_SimpleString(line);
if(ret != 0) {
... error at lineNum ...
}
lineNum++;
}
上面在下面的def语句中给出了错误(<--如下所示)
Python版本为2.7
import os
print "hello"
def foo(): # <-- PyRun_SimpleString fails here
print "hello again"
我想用它来显示if/it失败的脚本的行号。许多其他人似乎成功地使用了PyRun_SimpleString!
提前谢谢。
在这种情况下,您不会使用PyRun_SimpleString,因为它希望在一行中读取整个程序,而您将其分解为多行。
你应该只使用PyRun_SimpleFile(fileReference, scriptPath)
注意:您需要创建globals和locals对象,以上操作才能正常工作。
请参阅此
相关文章:
- 如果没有malloc,链表实现将失败
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 视图中的参数推导失败:take_while
- 链接到自行创建的dll失败
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- gcc和c++17的过载解析失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 从父数组测试用例构造二叉树失败
- LibGit2 SSH身份验证失败
- 如何让LLDB在成功时退出,在失败时等待
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- 生成MRPT库时cmake配置失败
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- variadic模板中的模板参数推导失败