[Tutor] Formatter

Don Arnold Don Arnold" <darnold02@sprynet.com
Sun Jan 19 00:21:02 2003


----- Original Message -----
From: "andy surany" <mongo57a@comcast.net>
To: "Don Arnold" <darnold02@sprynet.com>; "Pete Versteegen"
<pversteegen@gcnetmail.net>; "Bob Gailer" <ramrom@earthling.net>;
<Tutor@python.org>
Sent: Saturday, January 18, 2003 10:56 PM
Subject: Re: [Tutor] Formatter


> That worked..... however, maybe it's just me..., but I thought that
> "a10" would yield a "block" of 10 spaces for the alpha. I find that in
> my implementation, I have more than 10 - and according to your ruler, I
> think you do as well......
>
> Andy

Hmmm... I don't think so. From Pete's original post:

'''
My thoughts wander towards the way the Fortran language does it.  I'm
considered a function (class) that would be called as follows:
format((a, alf, i), "f10.2, a10, 10x, i5")
This would print the three items in the tuple according to the specifactions
listed between the quote marks, whee
f10.2 (float, 10 wide, 2 digits after decimal point)
a10 (alpha number of 10 wide
10x (1o blank spaces)
i5 (integer of 5 digits wide)
'''

Bob's code had 'a' being used to specify spaces and 'x' used for strings. I
switched their meanings back to match what Pete had said.

When I execute 'print format("-f10.2,-a10,10x,-i5", 5, 'qwer', 3)' in Idle,
I get:

'5.00' followed by 6 spaces (width of 10 bytes total)
'qwer' followed by 6 spaces (10 bytes)
10 spaces (10 bytes)
'3' followed by 4 spaces (5 bytes)

Looks okay to me.

Don