[Python-Dev] PyString_FromFormat
"Martin v. Löwis"
martin at v.loewis.de
Tue Jun 20 00:58:05 CEST 2006
Kristján V. Jónsson wrote:
> One thing I have often lamented having in PyString_FromFormat (and
> cousins, like PyErr_Format) is to be able to integrate PyObject
> pointers. Adding something like %S and %R (for str() and repr()
> respectively) seems very useful to me. Is there any reason why this
> isn´t there?
Not sure what the specific use case is, but I think I would use
PyString_Format instead, and use everything you can use in a %
operator. If you want to avoid explicit argument tuple building,
you can also write
static PyObject *fmt = NULL;
if (!fmt) fmt = PyString_FromString("Foo %s bar %s foobar %d");
res = PyMethod_Call(fmt, "__mod__", "(OOi)", o1, o2, 42);
Regards,
Martin
More information about the Python-Dev
mailing list