How string formats '%' operator is implemented?
<p>How does string formats '%' operator is implemented in CPython 2.7?</p>

<p>Can't find any reference in the <a href="https://docs.python.org/2/index.html" rel="nofollow">Python documentation</a>.</p>

<p>Well, I fact I found the topic: <a href="https://docs.python.org/2/c-api/conversion.html" rel="nofollow">String conversion and formatting</a>, for <code>PyOS_snprintf</code>and <code>PyOS_vsnprintf</code>. But not sure it match my question.</p>

<p>See also my question <a href="http://stackoverflow.com/questions/39203016/optional-keys-in-string-formats-using-operator">Optional keys in string formats using '%' operator?</a></p>

<p>The implementation is in the <a href="https://github.com/python/cpython/blob/2.7/Objects/stringobject.c#L4229" rel="nofollow"><code>PyString_Format</code></a> that is called by the <a href="https://github.com/python/cpython/blob/2.7/Objects/stringobject.c#L3743" rel="nofollow"><code>string_mod</code> function</a> in <code>Objects/stringobject.c</code>. The latter in turn is a slot method stored in <a href="https://github.com/python/cpython/blob/2.7/Objects/stringobject.c#L3761" rel="nofollow"><code>PyString_Type-&gt;tp_as_number-&gt;nb_remainder</code></a>. </p>

<p>The functions <code>PyOS_*snprintf</code> are not really related to the implementation of <code>str.__mod__</code>.</p>

python python-2.7 string-formatting