<div class="gmail_quote">2011/10/11 Hrvoje Niksic <span dir="ltr"><<a href="mailto:hrvoje.niksic@avl.com">hrvoje.niksic@avl.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":3l">An alternative I am fond of is to to avoid introducing a new type, and simply initialize a PyObject * and register its address. For example:<br>
<br>
PyObject *tmp;<br>
static PyObject *s_update; // pick a naming convention<br>
<br>
PY_IDENTIFIER_INIT(update);<br>
tmp = PyObject_CallMethodObj(result, s_update, "O", other);<br>
<br>
(but also PyObject_GetAttr(o, s_update), etc.)<br>
<br>
PY_IDENTIFIER_INIT(update) might expand to something like:<br>
<br>
if (!s_update) {<br>
s_update = PyUnicode_InternFromString("<u></u>update");<br>
_Py_IdentifierAdd(&s_update);<br>
}<br></div></blockquote><div><br></div><div>It should also check for errors; in this case the initialization is a bit more verbose:</div><div>if (PY_IDENTIFIER_INIT(update) < 0)</div><div> <return NULL or return -1 or goto error>;</div>
</div><div><br></div>-- <br>Amaury Forgeot d'Arc<br>
<div><br></div>