Coerce that can pay attention to type of operation

Huaiyu Zhu hzhu at yahoo.com
Tue Oct 3 17:20:59 EDT 2000


On 03 Oct 2000 17:19:50 +0200, Martin von Loewis
<loewis at informatik.hu-berlin.de> wrote: 
>hzhu at yahoo.com (Huaiyu Zhu) writes:
>
>> Or more generally,
>> 
>> "%80.2.3.5s" % a  == str(a, 80, 2, 3, 5)
>
>> which could be used to format more complicated objects in a very clean and
>> efficient way.
>
>That does not look very clean to me: too much magic. Instead, I'd
>write
>
>"%s" % a.str(80,2,3,5)
>
>I.e. I'd rather invoke an explicit function to pass arguments for
>fancy formatting.
>

Well, I was thinking about stuff like:

def typeseting(headers, blocks, format):
    i = 0
    for header, block in zip(headers, blocks):
        i += 1
        print format % (i, header, parse(block))

typeseting(headers, blocks, "%d. %s\n%80.2.3.5s")

The advantage is that everything the user wants to control is outside the
function, while every useless detail is inside, yet there is only one format
string to pass around.


Huaiyu



More information about the Python-list mailing list