Laurent LAPORTE
Laurent LAPORTE

Reputation: 22942

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 PyOS_snprintfand PyOS_vsnprintf. But not sure it match my question.

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

Upvotes: 0

Views: 101

Answers (1)

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__.

Upvotes: 2

Related Questions