Overriding member methods in __init__

c james cjames at callone.net
Mon Dec 3 14:28:50 EST 2007


Arnaud Delobelle wrote:
> Why not simply do:
> 
> class YesNo(object):
>     def __init__(self, which):
>         self.yesno = which and self.yes or self.no
>     def yes(self, val):
>         print 'Yes', val
>     def no(self, val):
>         print 'No', val
>     def __call__(self, val):
>         self.yesno(val)
> 
> I don't know which is fastest but I don't think there would be much
> difference.
> 
> --
> Arnaud
> 

This is more in the spirit of what I was trying to accomplish.
Originally, I was unaware the __call__ could not be assigned a different
method.




More information about the Python-list mailing list