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


Groups > comp.lang.python > #7992

Re: What is this syntax ?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <bsk16@case.edu>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'formatting': 0.07; 'python': 0.08; '>>>>': 0.09; 'dict': 0.09; 'host,': 0.09; 'port,': 0.09; 'skip:" 60': 0.09; 'pm,': 0.10; 'syntax': 0.11; 'wrote:': 0.14; 'roy': 0.16; 'specifier': 0.16; 'subject:syntax': 0.16; 'vito': 0.16; 'skip:" 40': 0.16; 'somewhere': 0.17; '2.3': 0.19; 'header:In-Reply-To:1': 0.21; 'seems': 0.21; 'item.': 0.23; "what's": 0.23; 'certainly': 0.25; 'string': 0.26; 'example': 0.27; 'message-id:@mail.gmail.com': 0.28; 'opposed': 0.29; 'instead': 0.29; 'sun,': 0.30; 'print': 0.31; 'to:addr:python- list': 0.33; 'php': 0.34; 'example,': 0.35; 'skip:" 10': 0.35; 'subject: ?': 0.35; 'subject:What': 0.35; 'using': 0.35; 'received:google.com': 0.37; 'something': 0.37; 'url:docs': 0.37; 'url:python': 0.38; 'received:74.125': 0.38; 'url:org': 0.38; 'data': 0.38; 'subject:: ': 0.38; 'easier': 0.39; 'to:addr:python.org': 0.39; 'format': 0.40; 'more': 0.60; 'url:3': 0.67; 'subject:this': 0.76; 'url:lib': 0.84
MIME-Version 1.0
In-Reply-To <itloct$1vl$1@dough.gmane.org>
References <4dfdfc99$0$715$426a34cc@news.free.fr> <4dfe10d1$0$28053$426a34cc@news.free.fr> <roy-2A6DC8.11394419062011@news.panix.com> <e724fc3e-8198-4fb7-b1d3-96834f3fa6bb@34g2000pru.googlegroups.com> <roy-DD0C35.16204819062011@news.panix.com> <itloct$1vl$1@dough.gmane.org>
Date Sun, 19 Jun 2011 15:29:41 -0700
Subject Re: What is this syntax ?
From Benjamin Kaplan <benjamin.kaplan@case.edu>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-Junkmail-Status score=10/49, host=mpv2.tis.cwru.edu
X-Junkmail-Signature-Raw score=unknown, refid=str=0001.0A020204.4DFE7857.0023,ss=1,fgs=0, ip=74.125.83.182, so=2010-12-23 16:51:53, dmn=2009-09-10 00:05:08, mode=single engine
X-Junkmail-IWF false
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.165.1308522593.1164.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 82.94.164.166
X-Trace 1308522593 news.xs4all.nl 49178 [::ffff:82.94.164.166]:57667
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7992

Show key headers only | View raw


On Sun, Jun 19, 2011 at 2:06 PM, Vito 'ZeD' De Tullio
<zak.mc.kraken@libero.it> wrote:
> Roy Smith wrote:
>
>> There's something nice about building up strings in-line, as
>> opposed to having to look somewhere to see what's being interpolated.
>> To give a more complex example, consider:
>>
>> print "$scheme://$host:$port/$route#$fragment"
>>
>> That certainly seems easier to me to read than:
>>
>> print "%s://%s:%s/%s#%s" % (scheme,
>>                             port,
>>                             host,
>>                             route,
>>                             fragment)
>>
>> because I don't have to line up the nth format specifier with the nth
>> data item.
>
> well, in python3 you can use dict to format strings
>
>>>> print("%(a)s" % {'a':'b'})
> b
>
> and you can achieve php interpolation via locals()
>
>>>> a = 'b'
>>>> print("%(a)s" % locals())
> b
>
>
> --
> By ZeD

That's a lot older than Python 3. Here's the example from the 2.3
docs:  http://docs.python.org/release/2.3/lib/typesseq-strings.html

Python 3 added a different syntax for string formatting, using .NET's
formatting syntax instead of C's.

"{scheme}://{host}:{port}/{route}#{fragment}".format(locals())

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


Thread

What is this syntax ? candide <candide@free.invalid> - 2011-06-19 15:41 +0200
  Re: What is this syntax ? Laurent Claessens <moky.math@gmail.com> - 2011-06-19 15:50 +0200
  Re: What is this syntax ? Noah Hall <enalicho@gmail.com> - 2011-06-19 14:58 +0100
  Re: What is this syntax ? Chris Angelico <rosuav@gmail.com> - 2011-06-20 00:03 +1000
  Re: What is this syntax ? candide <candide@free.invalid> - 2011-06-19 17:08 +0200
    Re: What is this syntax ? Roy Smith <roy@panix.com> - 2011-06-19 11:39 -0400
      Re: What is this syntax ? rusi <rustompmody@gmail.com> - 2011-06-19 09:58 -0700
        Re: What is this syntax ? Roy Smith <roy@panix.com> - 2011-06-19 16:20 -0400
          Re: What is this syntax ? Vito 'ZeD' De Tullio <zak.mc.kraken@libero.it> - 2011-06-19 23:06 +0200
            Re: What is this syntax ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-19 23:19 +0000
              Re: What is this syntax ? Vito 'ZeD' De Tullio <zak.mc.kraken@libero.it> - 2011-06-20 07:42 +0200
          Re: What is this syntax ? Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-06-19 15:29 -0700

csiph-web