Question about quoting style.

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Oct 2 01:54:07 CEST 2007


En Mon, 01 Oct 2007 19:10:11 -0300, James Stroud <jstroud at mbi.ucla.edu>  
escribi�:

> Bruno Desthuilliers wrote:
>> First point is that Python has no "variable interpolation".
>
> If you squint, it kind of does*:
>
>     >>> print '%(language)s has %(#)03d quote types.' % \
>               {'language': "Python", "#": 2}
>     Python has 002 quote types.
>
> You might think if the dict as a name space and the formatting operation
> as performing interpolation--but this take on formatting might be a  
> stretch.

Stretching more:

py> language="Python"
py> number=4
py> print '%(language)s has %(number)d quote types.' % locals()
Python has 4 quote types.

Or even more:

py> from string import Template
py> print Template('$language has $number quote  
types.').substitute(locals())
Python has 4 quote types.

-- 
Gabriel Genellina




More information about the Python-list mailing list