Fwd: [Tutor] variable from input?

Jeff Shannon jeff at ccvcorp.com
Tue Oct 26 04:17:11 CEST 2004


Lloyd Hugh Allen wrote:

>Perhaps the variable will later be a class with attributes describing
>a person, and it will make sense for each person to be her/his own
>variable? I could see that.
>  
>

But I fail to see how an assortment of unrelated variables with 
unpredictable names could possibly be an improvement over storing those 
class instances in a list or dictionary.  A dictionary makes them easier 
to store, easier to keep track of, and easier to access.  Creating 
variables with names from user input is going to be messier, more 
confusing, and *much* more likely to interfere with other aspects of the 
program.  (How many instances of this person class do we have, and what 
are their names?  In the user-generated variable names plan, you have to 
manually track all of this.  With a dict, you just use len(mydict) and 
mydict.keys().  Indeed, in order to track the names that are in use, 
you'd probably need to keep a list of them -- so instead of an 
assortment of variables and a list of variable names, why not just use a 
list of class instances that have a name as an attribute, or a dict of 
class instances with the name as the key?)

Jeff Shannon
Technician/Programmer
Credit International





More information about the Tutor mailing list