[Tutor] %string formatting FYI

michaelbaker@operamail.com michaelbaker@operamail.com
Mon, 29 Jan 2001 10:43:22 -0800


At 10:51 PM 1/26/01 -0500, you wrote:
>Date: Fri, 26 Jan 2001 17:40:38 -0800 (PST)
>From: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
>To: michaelbaker@operamail.com
>Cc: tutor@python.org
>Subject: [Tutor] Re: thank%s
>
>On Fri, 26 Jan 2001 michaelbaker@operamail.com wrote:
>
> > thanks once again (this is not the first time you have helped me out). I
> > almost looked at the Fancier Input/Output before sending to the list,
> > although now that I have I'm not so sure I wouldn't have sent to the list
> > anyway. I don't qutie follow this:
> >
> >  >>> import string
> >  >>> for x in range(1,11):
> > ...     print '%2d %3d %4d' % (x, x*x, x*x*x)
> > ...
> > 1       1       1
> > 2       4       8
> > 3       9       27
> > 4       16      64
> > 5       25      125
> > 6       36      216
> > 7       49      343
> > 8       64      512
> > 9       81      729
> > 10      100     1000
> >
> > %2d, %3d, %4d ???????????
>
>
>Actually, you'd be surprised; it's a documented BUG that string
>interpolation isn't explained!
>
>http://sourceforge.net/bugs/?func=detailbug&bug_id=121207&group_id=5470
>
>The Python implementers forgot to explain how it works, so don't worry if
>you can't find information on this stuff.

I found some info on pp. 40 of 'Learning Python' by O'Reilly - they call it 
string formatting. pp.41 includes formatting codes and the 'string' module.