2010-10-06 75 views
9

從cython使用C++標準std :: string的最佳方式是什麼?最後一個cython發行版本應該很容易,但我想知道爲什麼有std :: vector的包裝,而不是std :: string ...Cython C++和std :: string

回答

11

用Cython 0.16 includes wrappers for std::string,可與進口:

from libcpp.string cimport string 
+1

這似乎好多了。 – dsign 2012-08-14 15:58:52

+0

似乎我在OSX上使用Cython 0.16進行聲明與Linux上的Cython 0.17不兼容,使用OSX我無法將'string'轉換爲Python對象 – linello 2012-10-24 20:45:53

8

糟糕,這個問題已經在這裏掛了幾天了。最後,我做到了這一點:

cdef extern from "string" namespace "std": 
    cdef cppclass string: 
     char* c_str() 

這不是一個完整的解決方案,但它仍然做的事情。

+0

我想補充的字符串(字符*)也。這讓你前進和後退到Python字符串。 – meawoppl 2013-01-07 19:11:51