Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <list>
- #include <string>
- #include <iostream>
- #include "3rdparty/pybind11/embed.h"
- namespace py = pybind11;
- typedef std::list<std::list<std::string> > SheetData;
- SheetData CastToSheetData(PyObject *obj)
- {
- SheetData data;
- PyObject *iter = PyObject_GetIter(obj);
- if (!iter)
- return data;
- while (true) {
- std::list<std::string> aux_list;
- PyObject *next = PyIter_Next(iter);
- if (!next) {
- // nothing left in the iterator
- break;
- }
- PyObject *iter2 = PyObject_GetIter(next);
- if (!iter2)
- continue;
- while(true) {
- PyObject *next2 = PyIter_Next(iter2);
- if (!next2) {
- // nothing left in the iterator
- break;
- }
- PyObject* pyStrObj = PyUnicode_AsUTF8String(next2);
- char* zStr = PyBytes_AsString(pyStrObj);
- std::string foo(strdup(zStr));
- aux_list.push_back(foo);
- Py_DECREF(pyStrObj);
- }
- data.push_back(aux_list);
- }
- return data;
- }
- int main(int argc,char * argv[])
- {
- py::scoped_interpreter guard{};
- py::module _module = py::module::import("xlanalyser");
- py::object _tool = _module.attr("XlAnalyser")("sample.xls","E:/Computer Science/Python/Programs/Resources");
- SheetData data;
- py::object dataTable = _tool.attr("return_sheet")();
- data = CastToSheetData(dataTable.ptr());
- for(auto table:data)
- {
- for(auto list:table)
- {
- std::cout << list << "\t";
- }
- std::cout << std::endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment