Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'url:pipermail': 0.05; '%s"': 0.07; 'deprecated': 0.07; 'formatting': 0.07; 'function,': 0.07; 'python': 0.09; 'braces': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:method': 0.09; 'subject:string': 0.09; 'circumvent': 0.16; 'ignored,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:raw': 0.16; '{0}': 0.16; 'string': 0.17; 'wrote:': 0.17; 'thanks,': 0.18; '>>>': 0.18; '3.x': 0.22; "i'd": 0.22; 'originally': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'am,': 0.27; 'header:X-Complaints-To:1': 0.28; 'this?': 0.28; 'chris': 0.28; 'fri,': 0.30; 'url:python': 0.32; 'from:addr:yahoo.co.uk': 0.32; 'could': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'replaced': 0.35; 'subject:?': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'method': 0.36; 'anything': 0.36; 'uses': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'url:mail': 0.40; 'skip:u 10': 0.60; 'different': 0.63; 'therefore': 0.65; 'percent': 0.65; '2013': 0.84; 'hardly': 0.84; 'tex': 0.84; 'url:python-dev': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: raw format string in string format method? Date: Fri, 01 Mar 2013 00:00:19 +0000 References: <512f6585$0$3108$ba620e4c@news.skynet.be> <512f6cd7$0$3108$ba620e4c@news.skynet.be> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-92-18-29-221.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130215 Thunderbird/17.0.3 In-Reply-To: <512f6cd7$0$3108$ba620e4c@news.skynet.be> X-Antivirus: avast! (VPS 130228-0, 28/02/2013), Outbound message X-Antivirus-Status: Clean X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362095961 news.xs4all.nl 6930 [2001:888:2000:d::a6]:33226 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40203 On 28/02/2013 14:42, Helmut Jarausch wrote: > On Fri, 01 Mar 2013 01:22:48 +1100, Chris Angelico wrote: > >> On Fri, Mar 1, 2013 at 1:11 AM, Helmut Jarausch >> 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 ? > > Thanks, > Helmut. > Nope please see http://mail.python.org/pipermail/python-dev/2012-February/116790.html -- Cheers. Mark Lawrence