[Tutor] class instance with identity crisis

Alan Gauld alan.gauld at freenet.co.uk
Wed Jan 12 20:02:09 CET 2005


> 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 = Damson()
> weapon.dry()
> print weapon

Should work as expected...

Alan G.



More information about the Tutor mailing list