Jeff,
I get the impression that many pythonistas don't like string
interpolation. I've never seen a clear definition of why. Anyway, it's
easy enough to add with the Itpl [1] module:
import Itpl, sys
sys.stdout = Itpl.filter()
s, n, r = 0, 0, 0
print $s $n $r
0 0 0
x = Itpl.itpl($s $n $r)
Python 2.4 includes a string.Template class which does much the same thing as
Itpl.itpl():
from string import Template
s, n, r = '0', 12, 3.4
x = Template($s $n $r)
x.substitute(locals())
'0 12 3.4'
If you want to bundle this up in a pp() function you have to do some magic to get the
Bill Mill wrote:
Kent,
On Thu, 10 Feb 2005 13:43:21 -0500, Kent Johnson [EMAIL PROTECTED] wrote:
Python 2.4 includes a string.Template class which does much the same thing as Itpl.itpl():
I just didn't want to give an answer that only works in python 2.4,
and one furthermore which I have not
Although it's worse with:
newstr = s + ' ' + str(n) + ' ' + str(r)
You could try:
newstr = s + ' ' + `n` + ' ' + `r`
if you think thats better.
But `` is different to str() for some types.
Personally I prefer the formatting approach.
But in my mind nothing beats the Perl statement:
newstr
On Thu, 10 Feb 2005 19:28:26 -, Alan Gauld [EMAIL PROTECTED] wrote:
Although it's worse with:
newstr = s + ' ' + str(n) + ' ' + str(r)
You could try:
newstr = s + ' ' + `n` + ' ' + `r`
if you think thats better.
But `` is different to str() for some types.
Personally I prefer
Kent,
On Thu, 10 Feb 2005 13:43:21 -0500, Kent Johnson [EMAIL PROTECTED] wrote:
Python 2.4 includes a string.Template class which does much the same thing as
Itpl.itpl():
from string import Template
s, n, r = '0', 12, 3.4
x = Template($s $n $r)
x.substitute(locals())
'0 12
On Feb 10, 2005, at 19:50, Bill Mill wrote:
so #{variable} seems to do it. The googling shows that there are a
myriad of other ways, which I haven't even looked at. They all seem to
involve #{[symbol]variable} .
Here, [symbol] refers to the scope(?) of the variable. See the
discussion between me