[Python-3000] String formatting: Conversion specifiers
janssen at parc.com
Tue Jun 6 18:29:27 CEST 2006
> Here is a list of the conversion types that are currently supported by
> the % operator. First thing you notice is an eerie similarity between
> this and the documentation for 'sprintf'. :)
Yes. This is (or was) a significant advantage to the system. Many
people already had mastered the C/C++ printf system of specifiers, and
could use Python's with no mental upgrades. Is that no longer thought
to be an advantage?
> So there's no need to tell the system 'this is a float'
> or 'this is an integer'.
Except that the type specifier can affect the interpretation of the
rest of the format string. For example, %.3f means to print three
> The only way I could see this being useful is
> if you had a type and wanted it to print out as some different type -
> but is that really the proper role of the string formatter?
Isn't that exactly what the string formatter does? I've got a binary
value and want to express it as a different type, a string? Type
punning at the low levels is often a useful debugging tool.
More information about the Python-3000