Variables variable

2005-04-19 Thread Adriano Monteiro
Hi folks,

Someone know how to make variables variable like in PHP?
It's something like this:

$a = 'hi'
$$a = 'testing'
echo $hi
'testing'

Regards

-- 

Adriano Monteiro Marques
www.gopython.com.br
[EMAIL PROTECTED]

I'm FREE... Are you?
(PYTHON powered)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Variables variable

2005-04-19 Thread Reinhold Birkenfeld
Adriano Monteiro wrote:
 Hi folks,
 
 Someone know how to make variables variable like in PHP?
 It's something like this:
 
 $a = 'hi'
 $$a = 'testing'
 echo $hi
 'testing'

You are most certainly wanting to use dictionaries.

Or, if you work with attributes of an object, use getattr.

Reinhold
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Variables variable

2005-04-19 Thread Cameron Laird
In article [EMAIL PROTECTED],
Reinhold Birkenfeld  [EMAIL PROTECTED] wrote:
Adriano Monteiro wrote:
 Hi folks,
 
 Someone know how to make variables variable like in PHP?
 It's something like this:
 
 $a = 'hi'
 $$a = 'testing'
 echo $hi
 'testing'

You are most certainly wanting to use dictionaries.

Or, if you work with attributes of an object, use getattr.
.
.
.
I have a few comments on this:  Python can do essentially what
PHP does.  One means is the getattr() Reinhold cites.

HOWEVER, it's generally always a mistake to do so.  Dictionaries
are simply better.  AND THAT'S TRUE IN PHP, too.  I'm frankly 
disappointed in PHP leaders that they continue to promote this
variable-variable idiom.  As much as anything is certain in
the realm of stylistic expression, dictionaries are a superior
mechanism.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Variables variable

2005-04-19 Thread Ivan Van Laningham
Hi All--

Cameron Laird wrote:
 .
 I have a few comments on this:  Python can do essentially what
 PHP does.  One means is the getattr() Reinhold cites.
 
 HOWEVER, it's generally always a mistake to do so.  Dictionaries
 are simply better.  AND THAT'S TRUE IN PHP, too.  I'm frankly
 disappointed in PHP leaders that they continue to promote this
 variable-variable idiom.  As much as anything is certain in
 the realm of stylistic expression, dictionaries are a superior
 mechanism.


I don't know if this dictionary insight is Cameron's, but my experience
with Python has been that when I'm developing something from scratch,
I'll start with a big pile of cruft.  I think I'll need this.  Oh, and
that, too.  And what about this!  Oooh, cool!  Then I start carving
away the excess.  It usually takes two or three iterations at carving to
realize that whatever it is needs a dictionary.  I have never seen a
case where a dictionary didn't improve the design.  +1QOTW.

Well.  Storing a Mayan number/date as a dictionary turned out to be a
Spectacularly Bad Idea(tm);-), so I guess that's one case.

Metta,
Ivan
--
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours
-- 
http://mail.python.org/mailman/listinfo/python-list