Laurent LAPORTE Laurent LAPORTE - 5 months ago 36
Python Question

How string formats '%' operator is implemented?

How does string formats '%' operator is implemented in CPython 2.7?

Can't find any reference in the Python documentation.

Well, I fact I found the topic: String conversion and formatting, for

. But not sure it match my question.

See also my question Optional keys in string formats using '%' operator?


The implementation is in the PyString_Format that is called by the string_mod function in Objects/stringobject.c. The latter in turn is a slot method stored in PyString_Type->tp_as_number->nb_remainder.

The functions PyOS_*snprintf are not really related to the implementation of str.__mod__.