python vs ecmascript

Jeff Shannon jeff at ccvcorp.com
Tue Nov 27 13:52:06 EST 2001


Yong Lu wrote:

> David Bolen <db3l at fitlinxx.com> writes:
>
> >
> > One other useful mention is that the "%s" formatter is Python string
> > formatting operations will automatically apply str() to any non-string
> > object that it is handed.  So another approach could be:
> >
> >     print "integer i = %s" % i
> >
>
> A newbie question.  Where can I find documentation of this usage?
> I've searched a bit in the Python manual, but the only section
> on print doesn't mention this.

This is, of course, because it has nothing to do with print.  ;)  String
formatting is its own thing (though this is not terribly obvious), and can take
place without any usage of the print command, i.e.,

def format(number, string1, string2):
    return " %2d: (%s, %s)" % (number, string1, string2)

It *is* a bit difficult to find, perhaps, but usage of string formatting is
spelled out in the tutorial...  Actually, my biggest problem with the
documentation for it, is that it assumes familiarity with C printf()-style
format specifiers.

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list