On 10/18/07, <b class="gmail_sendername">Cory</b> <<a href="mailto:Cory.Leach@gmail.com">Cory.Leach@gmail.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br><br>I have a hopefully quick question about how to use Boost.Python to<br>export an Enum.<br>I am embedding python in C++ and am currently exporting my classes in<br>the following way:<br><br>nameSpace["OBJECT"] = class_<OBJECT>("OBJECT")
<br>        .def("getType", &OBJECT::getType)<br>        .def("setSprite", &OBJECT::setSprite);<br><br>So following this, I assumed that when exporting an enum the following<br>should work:<br>
<br>nameSpace["OBJECT_TYPE"] = enum_<OBJECT_TYPE>("OBJECT_TYPE")<br>                        .value("GENERIC_OBJECT",GENERIC_OBJECT)<br>                        .value("MAP_OBJECT",MAP_OBJECT)
<br>                        .value("TOTAL_OBJECT_TYPES",TOTAL_OBJECT_TYPES)<br>                        .export_values();<br><br>while the above compiles, it causes the following run time exception:<br><br>AttributeError: 'NoneType' object has no attribute 'OBJECT_TYPE'
<br><br>I took a look at the documentation and the only explanation I found<br>for enum appeared to be for extending python with modules. using the<br>following form:<br><br>BOOST_PYTHON_MODULE(enums)<br>{<br>    enum_<color>("color")
<br>        .value("red", red)<br>        .value("green", green)<br>        .export_values()<br>        .value("blue", blue)<br>        ;<br><br>}</blockquote><div><br>I think you should read next documentation:
<br><br><a href="http://boost.org/libs/python/doc/v2/scope.html">http://boost.org/libs/python/doc/v2/scope.html</a> <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I COULD do the above, I would prefer the first method if possible. I<br>however do not know how to import the module if it is statically<br>linked because doing a simple import does not work and I am not<br>familiar enough with the 
boost.python library, Python C API, or Python<br>itself to know how to set it up. So My question is this:<br><br>How can I either make the first method of adding an enum work and not<br>throw the exception, OR once I create the BOOST_PYTHON_MODULE in an
<br>embedded python c++ program how to I then import that module into my<br>embedded python?</blockquote><div><br><a href="http://boost.org/libs/python/doc/tutorial/doc/html/python/embedding.html">http://boost.org/libs/python/doc/tutorial/doc/html/python/embedding.html
</a><br>Embedding example:<br><a href="http://svn.boost.org/trac/boost/browser/trunk/libs/python/test/import_.cpp">http://svn.boost.org/trac/boost/browser/trunk/libs/python/test/import_.cpp</a><br></div><br>HTH<br></div><br>
-- <br>Roman Yakovenko<br>C++ Python language binding<br><a href="http://www.language-binding.net/">http://www.language-binding.net/</a>