where is the PyString_AsString in Python 3.0?
heweiwei at gmail.com
Sat Mar 7 03:32:58 CET 2009
On Mar 7, 9:34 am, BigHand <hewei... at gmail.com> wrote:
> On Mar 7, 3:50 am, Benjamin Peterson <benja... at python.org> wrote:
> > BigHand <heweiwei <at> gmail.com> writes:
> > > > There is no PyString_AsString. Everything
> > >> string is unicode now. (PyUnicode API)
> > > hello,Ben,
> > > could you give me an example? I almost know the
> > > PyUnicode API,but the
> > > docs of 3.0 is too brief for me.
> > PyString_FromString -> PyUnicode_FromString
> > PyString_Concat -> PyUnicode_Concat
> > etc...
> > To get a char * you have to explicitly encode the string with
> > PyUnicode_AsEncodedString.
> thanks Ben!
Finally I got the results now. This did take me 10 hours to solve
this. the docs of 3.0......
I hope this could help someone else:
PyObject *exc_type = NULL, *exc_value = NULL, *exc_tb = NULL;
PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
PyObject* str_exc_type = PyObject_Repr(exc_type); //Now a unicode
PyObject* pyStr = PyUnicode_AsEncodedString(str_exc_type, "utf-8",
const char *strExcType = PyBytes_AS_STRING(pyStr);
More information about the Python-list