String formatting char

Dale Strickland-Clark dale at
Wed Nov 21 12:03:52 CET 2001

Martin von Loewis <loewis at> wrote:

>Dale Strickland-Clark <dale at> writes:
>> Is there some way to alter the format escape character from % to
>> something else?
>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))

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