python - 如何将 python 列表发送到 C 字符串数组和 C 长整数数组?
问题描述
我试图将 python 列表发送到字符串/整数的 C 数组。我试图打印字符串数组,但它什么也没打印。
我实际上正在编写代码以使用 Python 从 .csv 文件中提取数据并尝试将此数据发送到 C 代码。当我尝试运行代码时,我收到了一些警告。
我从main(){}
like调用这个函数string_arr_conversion(NULL,pFunc)
,但我看不到任何打印,我收到下面解释的警告。
我已经调试过,发现if(!PyArg_ParseTuple(args, "o", &str_arr)) {retun NULL;}
当我调用上面的函数时,如果块返回null。
#include <Python.h>
static PyObject *string_arr_conversion(PyObject *self,PyObject *args){
PyObject *str_arr;
int i;
if(!PyArg_ParseTuple(args, "o", &str_arr)){
retun NULL;
}
int n=PyObject_Length(str_arr);
if(n<0) {
return NULL;
}
char arr[n][40];
for(i=0; i<n;i++){
PyObject *str=PyList_GetItem(str_arr,i);
arr[i][40]=PyLong_FromString(str,NULL,10);
}
for(i = 0; i<n; i++){
printf("\n Element is %c", arr[i]);
}
return arr;
}
我收到以下警告:
1.In string_err_conversion function passing argument 1 of 'PyLong_FromString' from incompatible pointer type.
note: expected 'char *' but argument is of type 'struct PyObject *'
assignment makes integer from pointer without cast.{here arr[i][MAX_STRING_SIZE]=PyLong_FromString(str,NULL,10); warnings are coming}
2.return from incompatible pointer type and function returns address of local variable.{In this line ::return arr;}
解决方案
推荐阅读
- c++ - 在成员函数中创建对象
- python - 尝试使用 python3 导入 pyautogui 时出错
- android - 如何从带有 FLAG_ACTIVITY_SINGLE_TOP 的通知导航到活动
- asp.net - 我需要能够通过 API 将 Chargify 订阅与我的 vb.net 网络表单站点集成
- javascript - 我可以在 Math.round 计算中使用从 DOM 收集的变量吗?
- android - 架构组件的视图模型类存在于哪个线程(UI/Background)?
- javascript - 两个 https 之间的 document.referrer 为空
- oracle-apps - Oracle Fusion Assets REST API 在哪里?
- sparql - SPARQL MINUS 命令未显示正确结果
- typescript - 从构造函数访问静态成员