Sam Kellett Sam Kellett - 1 year ago 93
Python Question

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.

Answer Source

In Boost.Python that would be something like

bp::object decimal = bp::import("decimal").attr("Decimal");
bp::object decimal_obj = decimal(1, 4);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download