[C++-sig] Conversion of python files to C++ ostreams
Michele De Stefano
micdestefano at gmail.com
Thu Apr 1 22:32:21 CEST 2010
Christopher,
I've figured out how you can use mds-utils.
The example is present into the documentation page of the
mds_utils::python::FileObj class.
So you have foo(ostream& os) and you would like to call it passing a
Python file object.
You cannot call
foo(oFileObj(...))
directly, simply because there is no converter for converting from a
Python object into an oFileObj object.
So, as shown into the doxygen example, you have to program a wrapper
like this one:
foo_wrap(boost::python::object pyfile) {
mds_utils::python::oFileObj fobj(py_file);
foo(fobj);
}
That's all, and it is quite simple.
I hope it helps.
Best regards.
Michele
2010/4/1 Christopher Bruns <cmbruns at stanford.edu>:
> On Tue, Mar 30, 2010 at 12:02 AM, Michele De Stefano
> <micdestefano at gmail.com> wrote:
>> there is a much easier way to treat a FILE* as a C++ stream. The easy
>> way is to use my open source library (mds-utils,
>> http://code.google.com/p/mds-utils/).
>
> If I have a C++ api like:
> void foo(ostream& os);
>
> using mds-utils, would I be able to wrap in python:
>
> foo(sys.stdout) # 1
>
> or would the python side need to be something more like:
>
> foo(oFileObj(sys.stdout)) # 2
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
--
Michele De Stefano
http://www.linkedin.com/in/micdestefano
http://code.google.com/p/mds-utils
http://xoomer.virgilio.it/michele_de_stefano
More information about the Cplusplus-sig
mailing list