raw format string in string format method?
Rick Johnson
rantingrickjohnson at gmail.com
Thu Feb 28 18:27:45 EST 2013
On Thursday, February 28, 2013 8:42:31 AM UTC-6, Helmut Jarausch wrote:
> Originally I had used percent-formatting
> But isn't it deprecated in Python 3.X ?
I don't know the current state of "percent formats" future, however, i can tell you that it should be deprecated ASAP!
Simpleminded Sam blubbered: """ But rick, how will we format strings that contain curly braces without the "percent format" option? We can't live without "percent formatting", we are but simple minded folks! *sky-falling* """
Easy Sam. You allow the user to pass "opener" and "closer" chars to the format function.
>>> "Elvis {has} <0> the {{{ building".format('left', opener='<', closer='>')
'Elvis {has} left the {{{ building'
For strings that contain all braces you could even create something unique:
>>> "(Elvis) {has} {S}0{E} the <building>".format('left', opener='{S}', closer='{E}')
'(Elvis) {has} left the <building>'
More information about the Python-list
mailing list