Christopher Dawson
Hi there,
I am wrapping a class with an operator()(int, int) which I'd like to make available in Python as a subscript operator, but haven't been able to find any documentation on this nor guess the appropriate .def
Is this possible and if so can anyone help?
Please bring your Boost.Python questions to the C++-sig: http://www.boost.org/more/mailing_lists.htm/#pysig. .def("__call__", &myclass::operator()) should work if you want round-paren subscripts. That won't help you if you need assignment, though. x(a, b) = 1 isn't legal Python. If you need assignment, you need square subscripts: x[a,b] = 1 For that, write thin wrapper functions and expose them as __getitem__ and __setitem__. See the Python docs (http://www.python.org/doc/ref/sequence-types.html) for more info. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com