Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!news.glorb.com!news-xfer.nntp.sonic.net!news.astraweb.com!border6.newsrouter.astraweb.com!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Re: new string formatting with local variables References: X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney Date: Tue, 07 Jun 2011 10:11:01 +1000 Message-ID: <87zklu1ox6.fsf@benfinney.id.au> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:1VPHYLdPz7lJ2N+s/pTHVU13aVU= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Lines: 19 Organization: Unlimited download news at news.astraweb.com NNTP-Posting-Host: 734c8688.news.astraweb.com X-Trace: DXC=>7?miTo=>7WD:=ciL5QPHRL?0kYOcDh@Z7^o:UA4R?cUH?AXjNnFo4Z]G;2>V^?kWSbEW9A[5UK?UNZ[SL`C\KgS5Nlk3k`1C:_ Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7120 Chris Rebert writes: > print "{solo} was captured by {jabba}".format(**locals()) # RIGHT I tend to use ‘u"foo {bar} baz".format(**vars())’, since ‘vars’ can also take the namespace of an object. I only need to remember one “give me the namespace” function for formatting. > You must use prefix-** in the call to unpack the mapping as keyword > arguments. Note that using locals() like this isn't best-practice. Who says so, and do you find their argument convincing? Do you have a reference for that so we can see why? -- \ “If you write the word ‘monkey’ a million times, do you start | `\ to think you're Shakespeare?” —Steven Wright | _o__) | Ben Finney