<div class="gmail_quote">2011/10/11 Hrvoje Niksic <span dir="ltr">&lt;<a href="mailto:hrvoje.niksic@avl.com">hrvoje.niksic@avl.com</a>&gt;</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, &quot;O&quot;, 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(&quot;<u></u>update&quot;);<br>
    _Py_IdentifierAdd(&amp;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) &lt; 0)</div><div>   &lt;return NULL or return -1 or goto error&gt;;</div>
</div><div><br></div>-- <br>Amaury Forgeot d&#39;Arc<br>
<div><br></div>