Why can't I subclass off of "date" ?

davidfinance at gmail.com davidfinance at gmail.com
Thu Aug 24 15:38:15 EDT 2006


Wow, you guys are fast.

Thanks Georg and Fredrik!!

Fredrik Lundh wrote:
> davidfinance at gmail.com wrote:
>
> > Ok, maybe this is a stupid question, but why can't I make a subclass of
> > datetime.date and override the __init__ method?
>
> __init__ controls initialization of an already constructed object.  to
> control construction, you need to override __new__:
>
>      http://pyref.infogami.com/__new__
>
> e.g.
>
> class A(date):
>      def __new__(cls, a, b, c, d):
>          print a, b, c, d
> 	return super(A, cls).__new__(cls, 2006, 12, 11)
> 
> </F>




More information about the Python-list mailing list