[Tutor] Re: Tutor digest, Vol 1 #108 - 1 msg

Danny Yoo dyoo@uclink4.berkeley.edu
Tue, 24 Aug 1999 22:54:49 -0700


On Tue, 24 Aug 1999, you wrote:

> Today's Topics:
> 
>   1. Initializing Tuples (Jonathon)
>         
> 	Basically, I am using tuples exactly as if they were the same as
> 	Pascal's Record type.   Which means that i can change the data 
> 	in them, so long as the type of data is not changed.   

You might want to try using dictionaries instead of tuples, if you're using the
data structure as a record like that:

student = { 'name':"John Doe", 'age', 42 }

However, I think it might be better to use a class as a way to collect your
data into a structure.  Classes are very much like records:

class student:
   name = "John Doe"
   age = 42

mystudent = student()  # This will create a new "instance" of the class
print mystudent.name  # you're able to access it like a record
# Also note that it has the default values we want
mystudent.name = "blah" 
mystudent2 = student()
print mystudent2.name  # Changing mystudent has no effect on mystudent2

The class method is cleaner, I think, and is closer in effect to what pascal
records do.

Hope this helps!


--
***
dyoo@uclink4.berkeley.edu
***