raw format string in string format method?

Rick Johnson rantingrickjohnson at gmail.com
Thu Feb 28 18:06:45 EST 2013


On Thursday, February 28, 2013 8:11:17 AM UTC-6, Helmut Jarausch wrote:
> Hi,
> 
> 
> 
> I'd like to print a string with the string format method which uses
> {0}, ...

/What/ uses "{0}" exactly? The substring you wish to inject or the format method? If the latter, we are aware of that!

> Unfortunately, the string contains TeX commands which use lots of
> braces. Therefore I would have to double all these braces just for the
> format method which makes the string hardly readable.

>>> "{0} balls".format("howdy{0} {doody}{10} had {wooden}")
'howdy{0} {doody}{10} had {wooden} balls'

But then why even bother to use the format method? Seriously, if you expect people to give a proper answer you need to not only explain the problem, but also, supply a simplified code example.

> Is there anything like a "raw" format string and any other means
> to circumvent this?

Even if there is, why would someone offer advice from such ambiguous input? Just because a "raw" format exists does not mean that /every/ poorly described problem will be solved using it.

Please provide adequate info.



More information about the Python-list mailing list