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
>
&
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
__
> 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
> 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
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
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
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
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
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