Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40133

Re: raw format string in string format method?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'output': 0.04; 'string.': 0.04; '%s"': 0.07; 'deprecated': 0.07; 'formatting': 0.07; 'function,': 0.07; 'python': 0.09; 'braces': 0.09; 'subject:method': 0.09; 'subject:string': 0.09; 'supported.': 0.09; 'whichever': 0.09; 'worse': 0.09; 'circumvent': 0.16; 'distinct': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ignored,': 0.16; 'it".': 0.16; 'methods;': 0.16; 'subject:raw': 0.16; '{0}': 0.16; 'string': 0.17; 'wrote:': 0.17; '>>>': 0.18; '3.x': 0.22; "i'd": 0.22; 'originally': 0.23; 'feature': 0.24; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'this?': 0.28; 'chris': 0.28; 'sets.': 0.29; 'no,': 0.29; 'fri,': 0.30; 'could': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'replaced': 0.35; 'received:209.85.220': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'method': 0.36; 'anything': 0.36; 'uses': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'most': 0.61; 'different': 0.63; 'therefore': 0.65; 'percent': 0.65; 'obvious': 0.71; '2013': 0.84; 'hardly': 0.84; 'tex': 0.84; '"one': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=+OBXUyUt9defXHQ2vVvJeDWVA3215rRWH42C9Ulh+/I=; b=DKlgGhtC/5qbs23zZ7WyYEAq3vVqU3HX+EKBVvaDhgaPDTWrD76Z1WUkmCzDZXIgoj 02xG4ES3T2nj3FmyHLa2nFb3Yx168CwZJC7LgtZ9puGXc3EHyGjFz8vmKqQlB8d7FUNM si1/QHIzm5JsovgsHRMdkidPsB0lhAIwfUyMefQ7gRrZsM6LHkRlVOBmMW1PpV59YIl7 S2GE/1DLu4mbfvPSiNS2V5zcFaVM/nU4lU1R8Ogwvf75hPQ3AduvWUQfFsxRMceFmmik R9WZgr9e/aOfODcoBExEMTrk8jxkaZvneJFxiJz0wxa9X5trxxz3yD0qa6VDR0GCSHJy YBJQ==
MIME-Version 1.0
X-Received by 10.58.56.161 with SMTP id b1mr2728250veq.42.1362064171579; Thu, 28 Feb 2013 07:09:31 -0800 (PST)
In-Reply-To <512f6cd7$0$3108$ba620e4c@news.skynet.be>
References <512f6585$0$3108$ba620e4c@news.skynet.be> <mailman.2646.1362061370.2939.python-list@python.org> <512f6cd7$0$3108$ba620e4c@news.skynet.be>
Date Fri, 1 Mar 2013 02:09:31 +1100
Subject Re: raw format string in string format method?
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2647.1362064180.2939.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1362064180 news.xs4all.nl 6977 [2001:888:2000:d::a6]:33847
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:40133

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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