RE: [Tutor] class instance with identity crisis

2005-01-12 Thread Barnaby Scott
rning lots! Thanks > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Behalf Of Alan Gauld > Sent: 12 January 2005 20:13 > To: Alan Gauld; Barnaby Scott; 'Tutor' > Subject: Re: [Tutor] class instance with identity crisis > &

Re: [Tutor] class instance with identity crisis

2005-01-12 Thread Alan Gauld
Whoops, I forgot to do an assignment... > So try > > def dry(self): return Prune() > > > class Prune: > > def __str__(self): > > return 'prune' > > > > weapon = Damson() > > weapon.dry() weapon = weapon.dry() > > print weapon > > Should work as expected... Alan G __

Re: [Tutor] class instance with identity crisis

2005-01-12 Thread Alan Gauld
> My opinion is : this is a very dangerous and "stupid" thing to do !!! No its quite common. Its why C++ for example allows you to write your own type convcersion functions! One area where I've used this is to convert faults to orders in a service management application. Its fairly common for a c

Re: [Tutor] class instance with identity crisis

2005-01-12 Thread Alan Gauld
> class Damson: > def __str__(self): > return 'damson' > > def dry(self): > self = Prune() You'll neeed to return it for the outside world to use it... So try def dry(self): return Prune() > class Prune: > def __str__(self): > return 'prune' > > weapon

Re: [Tutor] class instance with identity crisis

2005-01-12 Thread Danny Yoo
On Wed, 12 Jan 2005, Barnaby Scott wrote: > I was wondering how you can get an instance of a class to change itself > into something else (given certain circumstances), but doing so from > within a method. So: > > class Damson: > def __str__(self): > return 'damson' > > def dry(s

Re: [Tutor] class instance with identity crisis

2005-01-12 Thread Jeff Shannon
Barnaby Scott wrote: class Damson: def __str__(self): return 'damson' def dry(self): self = Prune() class Prune: def __str__(self): return 'prune' weapon = Damson() weapon.dry() print weapon [...] but something in me suggests it should produce prune After all, 's

Re: [Tutor] class instance with identity crisis

2005-01-12 Thread Yigal Duppen
On Wednesday 12 January 2005 12:10, Kent Johnson wrote: > A couple of ideas: > > You could have dry() return the new weapon: >def dry(self): > return Prune() > > then the client code would be > weapon = weapon.dry() > > > You could have the weapon encapsulate another object and delegate to

Re: [Tutor] class instance with identity crisis

2005-01-12 Thread Kent Johnson
A couple of ideas: You could have dry() return the new weapon: def dry(self): return Prune() then the client code would be weapon = weapon.dry() You could have the weapon encapsulate another object and delegate to it. Finally, you actually can change the class of an object just by assigning t

Re: [Tutor] class instance with identity crisis

2005-01-12 Thread Pierre Barbier de Reuille
My opinion is : this is a very dangerous and "stupid" thing to do !!! Try to imagine the complexity of your program for someone who is trying to understand how your code is working if an object suddenly change its own type !!! Clearly, if you want to change the type of an object, you want a con