Passing SWIG objects from C++ to Python gives 'SwigPyObject' object has no attribute <method>
I have a C++ project in Windows with many objects. I have used SWIG 3.0.10
successfully to expose a few of them and generate the PY and PYD files and
can create and work with the objects in Python. However, when I try to pass
the same type of object from C++ to Python I get the 'SwigPyObject' object
has no attribute <method> error.
And I create a new python code file to be called from the C++ program:
otherColor = color.Color(20,20,20)
The creation of a new object still works fine, but when using the Color
object which was passed from C++ to Python I get this error:
Traceback (most recent call last):
File "d:\swig\colorapp.py", line 6, in ColorTest
AttributeError: 'int' object has no attribute 'printMe'
The project can be downloaded from http://download.cmlabs.com/swigcolor.zip - open in VS2016 on a 64-bit Windows and compile for Release 64-bit (other
configs not configured correctly). Once compiled copy the ouput files
(color.py, _color.pyd, ColorApp.exe) and the python files (colorapp.py,
colortest.py) to d:\swig. This location can be changed in the ColorApp.cpp,
Python obviously knows about the Color object, but does not realise that the
object provided in the function parameter is a Color object.
If I in Python ask about the object types
I get the following output
How do I get Python to realise that the passed argument is of type Color?