[Tutor] variable from input?

Terry Carroll carroll at tjc.com
Tue Oct 26 02:49:33 CEST 2004

On Mon, 25 Oct 2004, Rene Lopez wrote:

> is it possible to have the user input something with a raw_input
> command, and then base upon the input make that into the name of a
> variable?
> for example:
> answer = raw_input("what is your name?")
> user types in Rene, and some how we end up with a variable named Rene?

I don't know the answer to this, and I suspect that if it's possible, it's 
not straightforward.

However, in general, anytime you're looking for something like this, the 
real answer is that you'd be better off using a dictionary, where the 
variable value is used as a key to the dictionary, i.e.,

The dictionary can index a number of objects of as much or as little 
complexity as you require, 

More information about the Tutor mailing list