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


Groups > comp.lang.python > #9118

Re: String concatenation vs. string formatting

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <bahamutzero8825@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; 'python,': 0.01; 'context': 0.04; ':-)': 0.06; 'formatting': 0.07; '%s"': 0.09; 'subject:string': 0.09; 'am,': 0.13; 'received:209.85.214.174': 0.13; 'received:mail-iw0-f174.google.com': 0.13; 'wrote:': 0.15; "'file')": 0.16; 'sajip': 0.16; 'subject:formatting': 0.16; 'subject:vs.': 0.16; 'tried:': 0.16; 'vinay': 0.16; 'primarily': 0.22; 'header:In-Reply-To:1': 0.22; 'least,': 0.23; 'versions': 0.23; 'keyword': 0.25; "python's": 0.25; 'received:209.85.214': 0.28; 'message-id:@gmail.com': 0.32; 'rather': 0.33; "i've": 0.33; 'to:addr:python-list': 0.34; 'instead': 0.34; 'header:User- Agent:1': 0.34; 'uses': 0.35; 'file': 0.36; 'using': 0.37; 'received:192': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; 'received:192.168.1': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; 'subject:. ': 0.66; 'preset': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=SG2Lk/nHRPWxzx3bEES/RIn6CAVi0+rzEPjwNjTP2iI=; b=LWmbwmWYEh7VptTUPK+6v0pQgqOM5wuJwkJ6c98/nr3Oc8HwxTB8ExSUScsmH82MAo 9vdiCKN/YsbHkyNrList8QkhEk2Fku2HDA9qLdCc7mBV85oX+0AXZSeCMTk4AtfnpuRg IkbGUNzPuYeEPmsZyQx1/hLY1t0CdQTs3dd+M=
Date Sat, 09 Jul 2011 17:02:32 -0500
From Andrew Berg <bahamutzero8825@gmail.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0
MIME-Version 1.0
To "comp.lang.python" <python-list@python.org>
Subject Re: String concatenation vs. string formatting
References <4E17661D.6020307@gmail.com> <loom.20110709T125838-983@post.gmane.org>
In-Reply-To <loom.20110709T125838-983@post.gmane.org>
X-Enigmail-Version 1.2
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.806.1310248971.1164.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1310248971 news.xs4all.nl 21839 [2001:888:2000:d::a6]:42442
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:9118

Show key headers only | View raw


On 2011.07.09 06:06 AM, Vinay Sajip wrote:
> In a logging context at least, using the form like
>
> logger.debug("formatting message with %s", "arguments")
>
> rather than
>
> logger.debug("formatting message with %s" % "arguments")
How would I do that with the newer formatting? I've tried:
> logger.info('Binary preset file {file} successfully stored.', {file :
> queue[0].preset_file})
(global name 'file' not defined)
and
> logger.info('Binary preset file {file} successfully stored.',
> file=queue[0].preset_file)
(unexpected keyword 'file')

> By the way, logging primarily uses %-formatting instead of the newer
> {}-formatting, because it pre-dates {}-formatting. In more recent versions of
> Python, all of Python's three formatting styles are supported - see
I've noticed. :-)
> log_formatter = logging.Formatter('{asctime} - __main__ - {funcName} -
> line {lineno} - {levelname} - {message}', style='{')

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: String concatenation vs. string formatting Andrew Berg <bahamutzero8825@gmail.com> - 2011-07-09 17:02 -0500

csiph-web