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


Groups > comp.lang.python > #40131

Re: raw format string in string format method?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'output': 0.04; 'string.': 0.04; '%s"': 0.07; 'formatting': 0.07; 'function,': 0.07; 'braces': 0.09; 'subject:method': 0.09; 'subject:string': 0.09; 'circumvent': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ignored,': 0.16; 'subject:raw': 0.16; '{0}': 0.16; 'string': 0.17; 'wrote:': 0.17; "i'd": 0.22; 'header:In- Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'this?': 0.28; '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; 'subject:?': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'method': 0.36; 'anything': 0.36; 'uses': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'different': 0.63; 'therefore': 0.65; 'percent': 0.65; '2013': 0.84; 'hardly': 0.84; 'tex': 0.84
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=sgPdwK8ndF5HPUOAv+Fhz3KdOQppVvhC4qL2+5U5Bcc=; b=LmJJY80OoSmAR8T7d6s8UQwcdd7nEI1KR0/92gzQkVZBe83gtx2htgWwqbFXTRMfVn G8Fe3TguW6+NaV1/epG7WUi5yVbNAnSmkXnEEiVSpT9WIF/IpRsBS1SZeULUWRMf8jFo aNdzyY6PMCbScrol10oKvR5z8Hhn9HWefuwD4kLj3X9K7lKIsH1jWW5nxfzPKsFaLYIi amOT5Nugk7gUWzJk2twXZCIIy5WgsoG2l7K2mus/FVdoWdKEKO9OPDfp4aoKozcAJZQT U42xftRMowPaU2+MfRcQmPVJ4oUrMz0lBp56pe0x4aP1BiRSB+06obf9eJ5ZKwWBvF+F x1fw==
MIME-Version 1.0
X-Received by 10.220.223.80 with SMTP id ij16mr2566867vcb.28.1362061368448; Thu, 28 Feb 2013 06:22:48 -0800 (PST)
In-Reply-To <512f6585$0$3108$ba620e4c@news.skynet.be>
References <512f6585$0$3108$ba620e4c@news.skynet.be>
Date Fri, 1 Mar 2013 01:22:48 +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.2646.1362061370.2939.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1362061370 news.xs4all.nl 6891 [2001:888:2000:d::a6]:45437
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:40131

Show key headers only | View raw


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

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