擅长:python、mysql、java
<p>根据这个openbabel文档,Python绑定没有提供打印<code>matrix3x3 object</code>的好方法是有原因的。^ {CD2>} C++类重载^ {< CD3>}运算符,SWIG将简单地忽略:</P>
<p><a href="http://openbabel.org/api/2.2.0/classOpenBabel_1_1matrix3x3.shtml" rel="noreferrer">http://openbabel.org/api/2.2.0/classOpenBabel_1_1matrix3x3.shtml</a></p>
<P>这意味着需要修改SWIG接口文件(查看<a href="http://www.swig.org/Doc1.3/SWIGPlus.html#SWIGPlus_class_extension" rel="noreferrer">http://www.swig.org/Doc1.3/SWIGPlus.html#SWIGPlus_class_extension</a>),以将^ {< CD4>}方法添加到C++中,其中^ {CD5>}包括^ {< CD3>}运算符。你的方法看起来很像</p>
<pre><code>std::string __str__() {
//make sure you include sstream in the SWIG interface file
std::ostringstream oss(std::ostringstream::out);
oss << (*this);
return oss.str();
}
</code></pre>
<P>我相信Syg在这种情况下将正确地处理C++的返回类型^ {< CD7>},但是如果不是,你可能需要回退一个字符数组。在</p>
<p>此时,您应该能够重新编译绑定,并重新运行Python代码。在^ {{CD2}}对象上调用^ {< CD8}}现在应该显示在C++中用^ {< CD3}}操作符显示的内容。在</p>