Right now, all the boost python wrapped C++ functions take positional arguments only. Not only that but the arguments aren't named so error messages and autogen'd docs can be pretty unhelpful. This also lets us set default values!
boost::python::arg (in the args.hpp header) can instruct boost set up kwargs for us. Then our wrapped functions will behave exactly like Python functions with named arguments.
Note, in the stream
boost::python::arg("a"), "b", "c", "d" creates arglist (a, b, c, d)
the call to arg is implied due to overloading of the comma operator. If you want to set default values, arg must be re-called, e.g.,: boost::python::arg("a")=1, "b", "c", boost::python::arg("d")=2 creates a function with arglist a=1, b, c, d=2
Right now, all the boost python wrapped C++ functions take positional arguments only. Not only that but the arguments aren't named so error messages and autogen'd docs can be pretty unhelpful. This also lets us set default values!
boost::python::arg
(in theargs.hpp
header) can instruct boost set up kwargs for us. Then our wrapped functions will behave exactly like Python functions with named arguments.Let's convert our functions.
For example, in autogen docs instead of:
we could have:
note
(object)arg1
isself
since these are class member functions.See: http://stackoverflow.com/questions/16660049/extracting-arguments-from-kwargs-in-boostpython http://www.boost.org/doc/libs/1_57_0/libs/python/doc/v2/args.html
Note, in the stream
boost::python::arg("a"), "b", "c", "d"
creates arglist(a, b, c, d)
the call to arg is implied due to overloading of the comma operator. If you want to set default values, arg must be re-called, e.g.,:boost::python::arg("a")=1, "b", "c", boost::python::arg("d")=2
creates a function with arglista=1, b, c, d=2