C API for str methods?

Martin v. Loewis martin at v.loewis.de
Fri Aug 2 10:09:57 CEST 2002


"Bjorn Pettersen" <BPettersen at NAREX.com> writes:

> Is there a reason why methods like str.split, str.join are not
> accessible through a C API? (PyUnicode seems to have a lot more of the
> functionality available through a C API although not all of them...)

In general, everything you can do in Python is accessible through the
C API.

>     # change last expression, e, to "magicVar = e"
>     lines = block.split('\n');

That will be

      lines = PyObject_CallMethod(block, "split", "s", "\n");

>     stmts = '\n'.join(lines[:-1])

That is

      PyObject_DelItem(lines, PyList_Size(lines) - 1);
      nl = PyString_FromStringAndSize("\n", 1);
      stmts = PyObject_CallMethod(nl, "join", "O", lines);

etc.

HTH,
Martin



More information about the Python-list mailing list