Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to access C++ class method exposed using boost python
    primarykey
    data
    text
    <p>I am new to Python and currently trying to expose some C++ APIs to Python using boost.python.</p> <p>I started with a simple class that is close to what i'm trying to achieve:</p> <pre><code>class BaseImpl { public: BaseImpl() {} virtual int f() { return 10; } }; class BaseImplWrap : public BaseImpl, public wrapper&lt;BaseImpl&gt; { public: int f() { return this-&gt;get_override("f")(); } }; </code></pre> <p>And exposed as follows:</p> <pre><code>BOOST_PYTHON_MODULE(test) { class_&lt;BaseImplWrap, boost::noncopyable&gt;("BaseImpl", init&lt;&gt;()) .def("f", &amp;BaseImpl::f) ; } </code></pre> <p>When I tried to access the exposed class method on PythonWin, I get the following error:</p> <pre><code>PythonWin 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32. Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information. &gt;&gt;&gt; import test &gt;&gt;&gt; a=test.BaseImpl() &gt;&gt;&gt; a.fFailed to format the args Traceback (most recent call last): File "C:\Program Files\Python\Lib\site-packages\pythonwin\pywin\idle\CallTips.py", line 130, in get_arg_text argText = inspect.formatargspec(*arg_getter(fob)) File "C:\Program Files\Python\lib\inspect.py", line 813, in getargspec raise TypeError('{!r} is not a Python function'.format(func)) TypeError: &lt;Boost.Python.function object at 0x000000000533ADF0&gt; is not a Python function </code></pre> <p>I then tried something simpler from the <a href="https://wiki.python.org/moin/boost.python/ExportingClasses" rel="nofollow">Exporting Class</a> tutorial, but still can't get it working with the following error:</p> <pre><code>namespace { class hello { public: hello(const std::string&amp; country) { this-&gt;country = country; } std::string greet() const { return "Hello from " + country; } private: std::string country; }; } BOOST_PYTHON_MODULE(test) { class_&lt;hello&gt;("hello", init&lt;std::string&gt;()) .def("greet", &amp;hello::greet) // Add a regular member function. ; } &gt;&gt;&gt; import test &gt;&gt;&gt; a=test.hello('world') &gt;&gt;&gt; a.greetFailed to format the args Traceback (most recent call last): File "C:\Program Files\Python\Lib\site-packages\pythonwin\pywin\idle\CallTips.py", line 130, in get_arg_text argText = inspect.formatargspec(*arg_getter(fob)) File "C:\Program Files\Python\lib\inspect.py", line 813, in getargspec raise TypeError('{!r} is not a Python function'.format(func)) TypeError: &lt;Boost.Python.function object at 0x0000000002FEACA0&gt; is not a Python function </code></pre> <p>Any idea why the exposed class methods are not recognized as python function? Is it something to do with my system configurations?</p> <p>I'm running on a <strong>Window 7 x64 machine</strong>, with <strong>Python 2.7</strong>, <strong>boost 1.54.0</strong> and <strong>MSVC 2012 x64</strong>.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload