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


Groups > comp.lang.python > #8007

Re: What is this syntax ?

Date 2011-06-20 10:18 +0300
From Claudiu Popa <cpopa@bitdefender.com>
Subject Re: What is this syntax ?
Newsgroups comp.lang.python
Message-ID <mailman.178.1308554725.1164.python-list@python.org> (permalink)

Show all headers | View raw


Hello,

Isn't this similar to php interpolation? And quite readable imo.

>>> import string
>>> template = string.Template("$scheme://$host:$port/$route#$fragment")
>>> template.substitute(scheme="http", host="google.com", port="80", route="", fragment="")
'http://google.com:80/#'
>>>


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)

  

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


Thread

Re: What is this syntax ? Claudiu Popa <cpopa@bitdefender.com> - 2011-06-20 10:18 +0300
  Re: What is this syntax ? Ben Finney <ben+python@benfinney.id.au> - 2011-06-21 08:19 +1000
    Re: new string-formatting preferred? (was "What is this syntax ?") Tim Chase <python.list@tim.thechases.com> - 2011-06-20 19:46 -0500
    Re: new string-formatting preferred? (was "What is this syntax ?") Terry Reedy <tjreedy@udel.edu> - 2011-06-20 22:17 -0400
    Re: new string-formatting preferred? (was "What is this syntax ?") Tim Chase <python.list@tim.thechases.com> - 2011-06-21 06:33 -0500
    Re: new string-formatting preferred? (was "What is this syntax ?") Terry Reedy <tjreedy@udel.edu> - 2011-06-21 18:19 -0400
    Re: new string-formatting preferred? (was "What is this syntax ?") Tim Chase <python.list@tim.thechases.com> - 2011-06-21 18:02 -0500

csiph-web