String formatting char

Dale Strickland-Clark dale at riverhall.NOTHANKS.co.uk
Wed Nov 21 12:03:52 CET 2001


Martin von Loewis <loewis at informatik.hu-berlin.de> wrote:

>Dale Strickland-Clark <dale at riverhall.NOTHANKS.co.uk> writes:
>
>> Is there some way to alter the format escape character from % to
>> something else?
>
>Sure.
>
>def format_with_tilde(msg, args):
>    assert msg.find('\200') == -1
>    msg = msg.replace('%','\200').replace('~','%')
>    msg = msg % args
>    return msg.replace('%','~').replace('\200','%')
>
>print format_with_tilde("~d is ~f% of ~d",(3,3.0/8,8))
>
>Regards,
>Martin

Yeah. I thought of that, too. But it's an awful cludge and much slower
than being able to use an alternative character directly.
--
Dale Strickland-Clark
Riverhall Systems Ltd



More information about the Python-list mailing list