Search code examples
pythonc++cboost-python

How do I create a Python Decimal object from C++?


...or any Python object that exists in an importable library. I have found PyDateTime_* functions in the documentation for creating objects from the datetime module, but I can't find anything to do with the python decimal module. Is this possible?

Looking for a Boost.Python way if there is one, but the native API's will suffice if not.


Solution

  • In Boost.Python that would be something like

    bp::object decimal = bp::import("decimal").attr("Decimal");
    bp::object decimal_obj = decimal(1, 4);