代码拉取完成,页面将自动刷新
同步操作将从 EVA/GETTAOBAO 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "pythonTest.h"
#include <QDebug>
#include <QMessageBox>
pythonTest::pythonTest():pModule(NULL)
{
// Py_SetPythonHome(L"C:\\Programs\\Python\\Python37-32");
Py_Initialize();
// QMessageBox::information(NULL, "Title", "1", QMessageBox::Yes, QMessageBox::Yes);
if (!Py_IsInitialized()) {
qDebug() << "inititalize failed";
}
else {
qDebug() << "inititalize success";
}
// QMessageBox::information(NULL, "Title", "python successful", QMessageBox::Yes, QMessageBox::Yes);
PyRun_SimpleString("import xlrd");
PyRun_SimpleString("import xlwt");
PyRun_SimpleString("import json");
PyRun_SimpleString("import ExcelParserTIF");
PyRun_SimpleString("import string");
PyRun_SimpleString("import jieba");
PyRun_SimpleString("import sqlite3");
pModule = PyImport_ImportModule("TIF");
if (!pModule)
{
qDebug() << "can not import python module file";
QMessageBox::information(NULL, "Title", "can not import python module file", QMessageBox::Yes, QMessageBox::Yes);
}
}
pythonTest::~pythonTest()
{
if(pModule)
Py_DECREF(pModule);
Py_Finalize();
}
QString pythonTest::getExcelInfo( QString& strFileName) const
{
QString strGetInfo;
if (!Py_IsInitialized()) {
printf("inititalize failed");
qDebug() << "inititalize failed";
return "FAIL";
}
else {
qDebug() << "inititalize success";
}
// PyObject * pModule = NULL;
PyObject * pFunc = NULL;
//pModule = PyImport_ImportModule("TIF");
if (!pModule)
{
qDebug() << "can not import python module file";
}
else
{
// PyRun_SimpleString("import json");
// PyRun_SimpleString("from collections import OrderedDict");
pFunc = PyObject_GetAttrString(pModule, "processdo");
if(pFunc)
{
PyObject* pRet = PyEval_CallObject(pFunc, Py_BuildValue("sss", "1","3","4"));
int a;
int b;
int size = PyDict_Size(pRet);
//char *ss =new char [1000];
if (pRet)
{
qDebug() << "分析数据成功";
// PyArg_ParseTuple(pRet, "is", &a,ss);
//strGetInfo = s;
}
else
{
qDebug() << "error";
strGetInfo ="打开的文件不是excel表,excel请用后缀名是.xlxs的文件。";
}
// ui->textEditLog->setPlainText(s);
}
}
// Py_Finalize();
return strGetInfo;
}
QString pythonTest::getExcel( QString &str) const
{
// Py_SetPythonHome(L"C:\\Programs\\Python\\Python37-32");
// Py_Initialize();
QString strGetInfo;
if (!Py_IsInitialized()) {
printf("inititalize failed");
qDebug() << "inititalize failed";
return "FAIL";
}
else {
qDebug() << "inititalize success";
}
PyObject * pFunc = NULL;
if (!pModule)
{
qDebug() << "can not import python module file";
}
else
{
// PyRun_SimpleString("import json");
// PyRun_SimpleString("from collections import OrderedDict");
pFunc = PyObject_GetAttrString(pModule, "getlist");
if(pFunc)
{
PyObject* pRet = PyEval_CallObject(pFunc, Py_BuildValue("(s)", str.toStdString().c_str()));
int a;
int b;
int size = PyDict_Size(pRet);
char *ss =new char [1000];
if (pRet)
{
qDebug() << "分析数据成功";
PyArg_ParseTuple(pRet, "s", &ss);
strGetInfo = ss;
Py_DECREF(pRet);
}
else
{
qDebug() << "error";
strGetInfo ="打开的文件不是excel表,excel请用后缀名是.xlxs的文件。";
}
// ui->textEditLog->setPlainText(s);
Py_DECREF(pFunc);
}
}
// Py_Finalize();
return strGetInfo;
}
QString pythonTest::save( QString &str)
{
QString strGetInfo;
if (!Py_IsInitialized()) {
printf("inititalize failed");
qDebug() << "inititalize failed";
Py_Initialize();
PyRun_SimpleString("import xlrd");
PyRun_SimpleString("import xlwt");
PyRun_SimpleString("import json");
PyRun_SimpleString("import ExcelParserTIF");
PyRun_SimpleString("import string");
PyRun_SimpleString("import jieba");
PyRun_SimpleString("import sqlite3");
pModule = PyImport_ImportModule("TIF");
if (!pModule)
{
qDebug() << "can not import python module file";
QMessageBox::information(NULL, "Title", "can not import python module file", QMessageBox::Yes, QMessageBox::Yes);
}
//return "FAIL";
}
else {
qDebug() << "inititalize success";
}
PyObject * pFunc = NULL;
if (!pModule)
{
qDebug() << "can not import python module file";
}
else
{
// PyRun_SimpleString("import json");
// PyRun_SimpleString("from collections import OrderedDict");
pFunc = PyObject_GetAttrString(pModule, "save");
if(pFunc)
{
PyObject* pRet = PyEval_CallObject(pFunc, Py_BuildValue("(s)", str.toStdString().c_str()));
int a;
int b;
// int size = PyDict_Size(pRet);
char *ss ;
if (pRet)
{
qDebug() << "分析数据成功";
// int kiki = PyArg_Parse(pRet, "s", &ss);
strGetInfo = "分析数据成功";
//qDebug() <<"dddd"<<strGetInfo;
Py_DECREF(pRet);
}
else
{
qDebug() << "error";
strGetInfo ="打开的文件不是excel表,excel请用后缀名是.xlxs的文件。";
}
// ui->textEditLog->setPlainText(s);
Py_DECREF(pFunc);
}
}
return strGetInfo;
};
QString pythonTest::smil(QString title, QString path ,int n)
{
QString strGetInfo;
if (!Py_IsInitialized()) {
printf("inititalize failed");
qDebug() << "inititalize failed";
return "FAIL";
}
else {
qDebug() << "inititalize success";
}
// PyObject * pModule = NULL;
PyObject * pFunc = NULL;
// pModule = PyImport_ImportModule("TIF");
if (!pModule)
{
qDebug() << "can not import python module file";
}
else
{
// PyRun_SimpleString("import json");
// PyRun_SimpleString("from collections import OrderedDict");
pFunc = PyObject_GetAttrString(pModule, "smil");
if(pFunc)
{
PyObject* pRet = PyEval_CallObject(pFunc, Py_BuildValue("(s,s,i)", path.toStdString().c_str(),
title.toStdString().c_str(),n));
int a;
int b;
// int size = PyDict_Size(pRet);
char *ss ;
if (pRet)
{
qDebug() << "分析数据成功";
int kiki = PyArg_Parse(pRet, "s", &ss);
strGetInfo = ss;
//qDebug() <<"dddd"<<strGetInfo;
Py_DECREF(pRet);
}
else
{
qDebug() << "error";
strGetInfo ="打开的文件不是excel表,excel请用后缀名是.xlxs的文件。";
}
// ui->textEditLog->setPlainText(s);
Py_DECREF(pFunc);
}
}
// Py_Finalize();
return strGetInfo;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。