What is this syntax ?

Roy Smith roy at panix.com
Sun Jun 19 16:20:48 EDT 2011


In article 
<e724fc3e-8198-4fb7-b1d3-96834f3fa6bb at 34g2000pru.googlegroups.com>,
 rusi <rustompmody at gmail.com> wrote:

> On Jun 19, 8:39 pm, Roy Smith <r... at panix.com> wrote:
> 
> > This is one of the (very) few places PHP wins over Python.  In PHP, I
> > would write this as
> >
> > print "'$x'"
> 
> 
> You dont find
> 
> >>> print '"%s"' % x
> 
> readable? Why?

I didn't say it wasn't readable, I said other things were easier to 
read.  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.



More information about the Python-list mailing list