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


Groups > comp.lang.python > #7091

new string formatting with local variables

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <jabba.laci@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.052
X-Spam-Evidence '*H*': 0.90; '*S*': 0.00; 'variable,': 0.07; 'skip:{ 20': 0.09; 'subject:string': 0.09; 'to:name:python mailing list': 0.09; 'this:': 0.10; 'captured': 0.16; 'subject:formatting': 0.16; 'idea?': 0.19; 'thanks,': 0.19; "doesn't": 0.25; 'string': 0.26; 'work.': 0.28; 'message-id:@mail.gmail.com': 0.28; 'looks': 0.31; 'hi,': 0.31; 'print': 0.31; 'to:addr:python-list': 0.33; 'received:209.85.212': 0.34; 'subject:new': 0.37; 'received:google.com': 0.37; 'something': 0.37; 'received:209.85': 0.37; 'but': 0.38; "i'd": 0.39; 'received:209': 0.39; 'i.e.': 0.39; 'subject:with': 0.39; 'to:addr:python.org': 0.39; 'han': 0.65; 'here': 0.66; 'solo': 0.68; 'subject:local': 0.84; 'received:209.85.212.178': 0.91; 'received:mail- px0-f178.google.com': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:from:date:message-id:subject:to :content-type; bh=TTveJog6v0qfvb+VHG8B7Agu2JjydsQ11e0f2Hyn7C0=; b=Md03fZu8bGyYm6TUwgL7FFOJdnMQeprNWs1Yy6+5WWr9OBKjr4f+vA1RbxBpeQyXSh evJ42p8NKcQKRKcyoEIXwNLjjJwyiko1ilvmlMYKFvyv+PfSUwauMGncjd2bgY59Tn1z o4aS3uA3MQcXiUGnOQDMlTC/h592WIT+/KSf8=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=F8vck77ftM1rKlw+An83R92EjkQh5FMPGyaZyuDgsm0ectjXGcjtyXRB6dqiRVAS72 pY+u7+5x7txHNxExtykAQQiJx9D3wnL6fARpT4nrqZQCm6JV08zyc83a5K25k5Z6unDD dsPV0xMicqJ+PfR/SwLiNx946DlEBpcahZgho=
MIME-Version 1.0
From Jabba Laci <jabba.laci@gmail.com>
Date Mon, 6 Jun 2011 12:15:35 -0400
Subject new string formatting with local variables
To Python mailing list <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
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.2490.1307376958.9059.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 82.94.164.166
X-Trace 1307376958 news.xs4all.nl 49042 [::ffff:82.94.164.166]:44479
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7091

Show key headers only | View raw


Hi,

I'd like to simplify the following string formatting:

solo = 'Han Solo'
jabba = 'Jabba the Hutt'
print "{solo} was captured by {jabba}".format(solo=solo, jabba=jabba)
# Han Solo was captured by Jabba the Hutt

What I don't like here is this: "solo=solo, jabba=jabba", i.e. the
same thing is repeated. In "solo=solo", the left part is a key and the
right part is the value of a local variable, but it looks strange.

I'd like something like this:
print "{solo} was captured by {jabba}".format(locals())        # WRONG!

But it doesn't work.

Do you have any idea?

Thanks,

Laszlo

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


Thread

new string formatting with local variables Jabba Laci <jabba.laci@gmail.com> - 2011-06-06 12:15 -0400
  Re: new string formatting with local variables Steve Crook <steve@mixmin.net> - 2011-06-06 18:30 +0000
    Re: new string formatting with local variables Ethan Furman <ethan@stoneleaf.us> - 2011-06-06 11:57 -0700
    RE: new string formatting with local variables "Prasad, Ramit" <ramit.prasad@jpmchase.com> - 2011-06-06 16:21 -0400
    Re: new string formatting with local variables Ethan Furman <ethan@stoneleaf.us> - 2011-06-06 14:07 -0700

csiph-web