Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7122
| 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 | <ian.g.kelly@gmail.com> |
| 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 | <BANLkTi=VUwFDv5otq=7CMngbWzHy3Fo50A@mail.gmail.com> <mailman.2491.1307377282.9059.python-list@python.org> <87zklu1ox6.fsf@benfinney.id.au> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Mon, 6 Jun 2011 18:38:10 -0600 |
| Subject | Re: new string formatting with local variables |
| To | Ben Finney <ben+python@benfinney.id.au> |
| 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 <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.2512.1307407121.9059.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On Mon, Jun 6, 2011 at 6:11 PM, Ben Finney <ben+python@benfinney.id.au> wrote:
> Chris Rebert <clp2@rebertia.com> 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.
If you're using an object namespace, then you can just do this:
print("{o.solo} was captured by {o.jabba}".format(o=self))
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: new string formatting with local variables Chris Rebert <clp2@rebertia.com> - 2011-06-06 09:21 -0700
Re: new string formatting with local variables Ben Finney <ben+python@benfinney.id.au> - 2011-06-07 10:11 +1000
Re: new string formatting with local variables Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-06 18:31 -0600
Re: new string formatting with local variables Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-06 18:38 -0600
Re: new string formatting with local variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-07 03:57 +0000
Re: new string formatting with local variables Ben Finney <ben+python@benfinney.id.au> - 2011-06-07 17:47 +1000
csiph-web