[Python-3000] String formatting: Conversion specifiers
tanzer at swing.co.at
Wed Jun 7 15:56:24 CEST 2006
Nick Coghlan <ncoghlan at gmail.com> wrote:
> Bill Janssen wrote:
> >> 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?
> It's possible to define the format string independently of the type specifier
> - its just that some of the fields only have an effect when certain type
> specifiers are used (e.g. precision is ignored for string and integer type
For strings, it isn't (not by Python at least):
Python 2.4.2 (#1, May 30 2006, 13:47:24)
[GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "%3.3s" % "abcdef"
Christian Tanzer http://www.c-tanzer.at/
More information about the Python-3000