Derived class problem

Greg Ewing look at replyto.address.invalid
Mon May 27 01:14:46 EDT 2002


Geiger Ho wrote:
> 
> class A:
>   def method1(self):
>       ...
>       child = A()
>       ...
> 
> class B(A):
>   pass
> 
>   When I call B.method1(), I will create an A child. But this is not I
> intend to do. I wanna create a B child.

   child = self.__class__()

-- 
Greg Ewing, Computer Science Dept, 
University of Canterbury,	  
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list