What is this syntax ?
Vito 'ZeD' De Tullio
zak.mc.kraken at libero.it
Sun Jun 19 17:06:36 EDT 2011
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
More information about the Python-list
mailing list