[Tutor] multiple class instances

Deirdre Saoirse deirdre@deirdre.net
Mon, 10 May 1999 12:44:50 -0400 (EDT)


self.choice = 'foo' will create an instance variable for that class.
Assigning it to choice will be global across all instances.

On Mon, 10 May 1999, K P wrote:

> How can I create multiple class instances (objects?) that do not share
> the same data? For example the following class:
> 
> class Spam:
> 	choice = "I\'ll have the spam"
> 
> if I create an instance:
> 
> spam1 = Spam
> 
> Then reassign a data member:
> 
> spam1.choice = "Do you have anything besides spam?"
> 
> Then create a new instance:
> 
> spam2 = Spam
> 
> Then print spam2.choice, it will print the value assigned above:
> 
> spam2.choice
> 'Do you have anything besides spam?'
> 
> So my question, restated, is how can I have spam1 and spam2 based on Spam,
> and yet have different data for the same variables/members?
> 
> further example, I would like this be the printout for spam1.choice and
> spam2.choice:
> spam1.choice
> 'Do you have anything besides spam?'
> spam2.choice
> 'I'll have the spam'
> 
> disclaimer:
> 	It's been awhile since I saw the spam sketch so if I mis-quoted it......
> Ken
> 

_Deirdre   *   http://www.linuxcabal.org   *   http://www.deirdre.net
"Everyone needs the luff of a fine penguin" -- Mikey