[Tutor] variable from input?
alan.gauld at freenet.co.uk
Tue Oct 26 09:47:14 CEST 2004
> On Mon, 25 Oct 2004 19:53:22 -0400, Rene Lopez <renx99 at gmail.com>
> > 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?
This is a very common question from beginners and 'I address it
in the OOP topic of my tutor. But basically its nearly always a
At the >>> prompt it makes a little bit of sense because you use
variable names dynamically but if you are writing programs into
files for future execution your code will not know about the new
name. The new variable will be effectively useless.
It is much better, as already suggested, to use a dictionary of
Author of the Learn to Program web tutor
More information about the Tutor