I changed the code one month ago and im stucking at the same error which i described below. I dont find a pretty simple example how to expose an fstream object with Boost.Python to Python to solve my explained problem
In short words i just want to expose a Class that contains an I/O object with functions write / open / close. In Pyton i want to do these steps:
- open File1
- open File2
- open File3
- write to File1
- write to File2
- write to File3
- close files
C/C++ Code
////// I N C L U D E S //////
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python.hpp>
#include <fstream>
#include <string.h>
////////////////////////////
using namespace std;
struct BoostXML_IO
{
ofstream File;
void writeFile(const string& strToWrite)
{
this->File.write(strToWrite.data(), strToWrite.size());
}
void openFile(const string& path)
{
this->File.open(path, ios::app);
}
void closeFile()
{
this->File.close();
}
};
BOOST_PYTHON_MODULE(BoostXML_IO)
{
using namespace boost::python;
class_<BoostXML_IO, boost::noncopyable>("BoostXML_IO")
.def("writeFile", &BoostXML_IO::writeFile)
.def("openFile", &BoostXML_IO::openFile)
.def("closeFile", &BoostXML_IO::closeFile)
;
}
This code always compiles without an error but finally in Python i always get the following error when i try to invoke one of the functions in the prompt line.
ERROR code
>>> import BoostXML_IO
>>> File1 = BoostXML_IO
>>> File = BoostXML_IO.BoostXML_IO.openFileFailed to format the args
Traceback (most recent call last):
File "C:\app\tools\Python25\Lib\site-packages\pythonwin\pywin\idle\CallTips.py", line 130, in get_arg_text
argText = inspect.formatargspec(*arg_getter(fob))
File "C:\app\tools\Python25\Lib\inspect.py", line 743, in getargspec
raise TypeError('arg is not a Python function')
TypeError: arg is not a Python function
(
Thank you a lot in advance !