String formatting char
Martin von Loewis
loewis at informatik.hu-berlin.de
Tue Nov 20 07:11:03 EST 2001
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
More information about the Python-list
mailing list