Smith, Jeff wrote:
But in my mind nothing beats the Perl statement:
newstr = "$s $n $r";
for clarity, ease of use, and maintainability.
Only a little ease of use is lost with the following in Python, clarity
and maintainability are kept, and it even will let you format the output
(as in # of deci
On Feb 10, 2005, at 19:50, Bill Mill wrote:
so "#{} .
Here, [symbol] refers to the scope(?) of the variable. See the
discussion between me and Alan on this topic a while ago -- the use of
these symbols being his main criticism of Ruby.
foo is a local variable
$foo is a global variable
@foo is a
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.substit
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.
>
> Person
> 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:
> new
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 test
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
Sorry for the double post; I forgot one thing:
On Thu, 10 Feb 2005 10:43:28 -0500, Bill Mill <[EMAIL PROTECTED]> wrote:
> 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 I
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.
To all those who talked about hating the symbology in Perl and the
suggestion that it should be removed from a later version. I just
remembered what you get for that symbology that I really do like about
Perl: variable interpolation in strings:
C:
sprintf(newstr,"%s %d %f",s,n,r);
Becomes a litt
10 matches
Mail list logo