473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Variables variable

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
py********@gmail.com

I'm FREE... Are you?
(PYTHON powered)
Jul 19 '05 #1
3 1182
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
Jul 19 '05 #2
In article <3c*************@individual.net>,
Reinhold Birkenfeld <re************************@wolke7.net> 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.

Jul 19 '05 #3
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/worksh...oceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: gabor | last post by:
hi, as far as i know in python there aren't any private (i mean not accessible from the outside of the object) methods/fields. why? in java/c++ i can make a method private, this way...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
15
by: CR | last post by:
I've noticed that the trend these days is to declare variables in the middle of code instead of at the top. What is the advantage of this? It seems like it makes it hard to reuse variables. Here...
28
by: Dennis | last post by:
I have a function which is called from a loop many times. In that function, I use three variables as counters and for other purposes. I can either use DIM for declaring the variables or Static. ...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
6
by: Chris Carlen | last post by:
Hi: I have an embedded system, platform: TI TMS320F2812 32-bit integer DSP. A module (.c file) contains external (to the funcs in that module) variables which are used to affect the operation...
19
by: LucasLondon | last post by:
Hi there, First of all apologies for the long post. Hope someone can offer some advice. I have about 200 columns of time series data that I need to perform a correlation analysis on in terms...
16
by: RB | last post by:
Hi clever people :-) I've noticed a lot of people stating not to use static variables with ASP.NET, and, as I understand it, the reason is because the variable is shared across user sessions -...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.