Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'namespace': 0.09; 'object.': 0.09; 'skip:{ 20': 0.09; 'subject:string': 0.09; 'pm,': 0.10; 'this:': 0.10; 'wrote:': 0.14; 'captured': 0.16; 'finney': 0.16; 'formatting.': 0.16; 'namespace,': 0.16; 'rebert': 0.16; 'subject:formatting': 0.16; 'cc:addr:python-list': 0.17; 'mon,': 0.17; 'cheers,': 0.19; 'writes:': 0.19; 'header:In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'received:209.85.161.46': 0.23; 'received:mail- fx0-f46.google.com': 0.23; 'skip:b 20': 0.23; 'function': 0.25; 'received:209.85.161': 0.26; 'object': 0.26; 'message- id:@mail.gmail.com': 0.28; 'import': 0.29; 'cc:addr:python.org': 0.30; 'looks': 0.31; 'print': 0.31; 'tend': 0.32; 'chris': 0.34; 'using': 0.35; 'subject:new': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.37; 'but': 0.38; 'subject:: ': 0.38; 'doing': 0.39; 'received:209': 0.39; 'subject:with': 0.39; 'subject:local': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=QHTRgUG99s1m7NFyjVr+e4am4DGvJC5p5jt+Fq16trY=; b=q4PzbZeaVEl0gXGeqhtLxS91P6/ioN4ovnTTY03RDThqzwYniker6RqNnjS0AcKec1 oprxO3xAGdDMra2UXJ6/+c681GSxD2LyqhnxXD65ueh3FQyv17F68Do6qLXaJTqzrhoM 1+7iSmwXQ+4Uo7tN6x4IrLAmxgZnO3DpHeXIo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=MDLFpKVWjh+kBDr147sUjJ/lzsQoL5693CYfxfRxp+gvYS1gGkq4paT7KqBOiiVNp1 pR5JHSgmcjvh6ippbgXlDzZH+fR8KniLMlCPhdnbGp0gT1jsX4Qcgwp8bj9x6CTkdfYR zbnsV7VRv6bY3RpqJ2dUKfoJL1Asd/hk05/so= MIME-Version: 1.0 In-Reply-To: <87zklu1ox6.fsf@benfinney.id.au> References: <87zklu1ox6.fsf@benfinney.id.au> From: Ian Kelly Date: Mon, 6 Jun 2011 18:38:10 -0600 Subject: Re: new string formatting with local variables To: Ben Finney Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 21 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307407121 news.xs4all.nl 49041 [::ffff:82.94.164.166]:48845 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7122 On Mon, Jun 6, 2011 at 6:11 PM, Ben Finney wro= te: > Chris Rebert writes: > >> print "{solo} was captured by {jabba}".format(**locals()) # RIGHT > > I tend to use =91u"foo {bar} baz".format(**vars())=92, since =91vars=92 c= an also > take the namespace of an object. I only need to remember one =93give me > the namespace=94 function for formatting. If you're using an object namespace, then you can just do this: print("{o.solo} was captured by {o.jabba}".format(o=3Dself)) That looks a lot cleaner to me than passing in **vars(self). For locals(), I can see the appeal, but I tend to avoid it because it has the same icky feeling as doing an import *. Cheers, Ian