Re: [Tutor] Perl Symbology (was: Are you allowed to shoot camels?)

2005-02-10 Thread Hugo González Monteverde
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 decimal places)

newstr = "%{s}s %(n)s %(r)s"%locals()
If you cannot assume a type you can always just use %s...
Hugo
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Perl Symbology (was: Are you allowed to shoot camels?)

2005-02-10 Thread Max Noel
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 an instance variable
@@foo is a class variable
FOO is a constant (which can be modded into global, instance or class 
with the appropriate use of $, @ or @@)

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Perl Symbology (was: Are you allowed to shoot camels?)

2005-02-10 Thread Bill Mill
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 the formatting approach.
> 
> > But in my mind nothing beats the Perl statement:
> > newstr = "$s $n $r";
> 
> Perl is king of string processing in modern scripting,
> without a doubt. But even here the $ prefix could have
> been used for that specific purpose without insisting
> it be used everywhere else!
> 
> BTW Anyone recall how Ruby does this?

I don't know ruby at all, but a quick google and 30 interpreter seconds later:

irb(main):001:0> x = 12
=> 12
irb(main):002:0> '$x'
=> "$x"
irb(main):003:0> "$x"
=> "$x"
irb(main):004:0> "#{$x}"
=> ""
irb(main):005:0> "#{x}"
=> "12"
irb(main):006:0> '#{x}'
=> "#{x}"

so "#{} .

Peace
Bill Mill
bill.mill at gmail.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Perl Symbology (was: Are you allowed to shoot camels?)

2005-02-10 Thread Alan Gauld
> 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 = "$s $n $r";

Perl is king of string processing in modern scripting, 
without a doubt. But even here the $ prefix could have 
been used for that specific purpose without insisting 
it be used everywhere else!

BTW Anyone recall how Ruby does this?

Alan G.
Too lazy to look it up!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Perl Symbology (was: Are you allowed to shoot camels?)

2005-02-10 Thread Bill Mill
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 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")
> >>> x
> '0 0 0'
> 

This works with arbitrary data types too, to be truer to your example:

>>> s, n, r = '0', 12, 3.4
>>> x = Itpl.itpl("$s $n $r")
>>> x
'0 12 3.4'

Peace
Bill Mill
bill.mill at gmail.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Perl Symbology (was: Are you allowed to shoot camels?)

2005-02-10 Thread Bill Mill
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")
>>> x
'0 0 0'

And, of course, you can give Itpl.itpl a nicer name; I usually call it
pp(). If you don't need to change the behavior of the "print"
statement, then you don't need the Itpl.filter() line.

[1]  http://lfw.org/python/Itpl.py

Peace
Bill Mill
bill.mill at gmail.com


On Thu, 10 Feb 2005 10:22:51 -0500, Smith, Jeff <[EMAIL PROTECTED]> wrote:
> 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 little nicer in Python with:
> newstr = '%s %d %f' % (s,n,r)
> 
> Although it's worse with:
> newstr = s + ' ' + str(n) + ' ' + str(r)
> 
> But in my mind nothing beats the Perl statement:
> newstr = "$s $n $r";
> 
> for clarity, ease of use, and maintainability.
> 
> Jeff
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor