Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40133
| References | <512f6585$0$3108$ba620e4c@news.skynet.be> <mailman.2646.1362061370.2939.python-list@python.org> <512f6cd7$0$3108$ba620e4c@news.skynet.be> |
|---|---|
| Date | 2013-03-01 02:09 +1100 |
| Subject | Re: raw format string in string format method? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2647.1362064180.2939.python-list@python.org> (permalink) |
On Fri, Mar 1, 2013 at 1:42 AM, Helmut Jarausch <jarausch@skynet.be> wrote:
> On Fri, 01 Mar 2013 01:22:48 +1100, Chris Angelico wrote:
>
>> On Fri, Mar 1, 2013 at 1:11 AM, Helmut Jarausch <jarausch@skynet.be>
>> wrote:
>>> Hi,
>>>
>>> I'd like to print a string with the string format method which uses
>>> {0}, ...
>>>
>>> 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.
>>>
>>> Is there anything like a "raw" format string and any other means to
>>> circumvent this?
>>
>> You could use a different string formatting function, such as
>> percent-formatting:
>>
>> "Hello, {0}, this is %s" % some_string
>>
>> The {0} will be output literally, and the %s will be replaced by the
>> string. Braces are ignored, percent signs are significant.
>>
>> ChrisA
>
> Originally I had used percent-formatting
> But isn't it deprecated in Python 3.X ?
No, it's still fully supported. Every now and then someone suggests
that it's worse than .format() for some reason or another, but the
fact is that it's not going away. Use whichever one makes the most
sense.
Yes, this is a slight violation of "one obvious way to do it". But
it's handy to have both format methods; they have overlapping but
distinct feature sets.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
raw format string in string format method? Helmut Jarausch <jarausch@skynet.be> - 2013-02-28 14:11 +0000
Re: raw format string in string format method? Chris Angelico <rosuav@gmail.com> - 2013-03-01 01:22 +1100
Re: raw format string in string format method? Helmut Jarausch <jarausch@skynet.be> - 2013-02-28 14:42 +0000
Re: raw format string in string format method? Chris Angelico <rosuav@gmail.com> - 2013-03-01 02:09 +1100
Re: raw format string in string format method? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-28 15:27 -0800
Re: raw format string in string format method? Chris Angelico <rosuav@gmail.com> - 2013-03-01 15:29 +1100
Re: raw format string in string format method? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-03-01 00:00 +0000
Re: raw format string in string format method? Peter Otten <__peter__@web.de> - 2013-02-28 16:41 +0100
Re: raw format string in string format method? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-28 15:06 -0800
csiph-web