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

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

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 it. As

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(self):

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

RE: [Tutor] class instance with identity crisis

2005-01-12 Thread Barnaby Scott
! 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 Whoops, I forgot to do an assignment