Replacement for _PyString_Resize in Python 3

I am porting a module that uses C to extend Python functionality from 2.x to 3 and cannot find any links in the documents on how to resize a string, only how to get its size:

http://docs.python.org/py3k/c-api/unicode.html?highlight=pyunicode#PyUnicode_GetSize

How do I convert this code:

_PyString_Resize(&buffer, (int)res);

to what python 3 can understand?

+3
source share
1 answer

Unless documented on the page you linked, unicodeobject.c contains as

int _PyUnicode_Resize(PyUnicodeObject **unicode, Py_ssize_t length) 

and wrapper

int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
{
    return _PyUnicode_Resize((PyUnicodeObject **)unicode, length);
}

I do not know if the lack of documentation is an oversight or calm fatigue (I never used any of them).

+5
source

All Articles