How to subclass datetime?
Tim Peters
tim_one at email.msn.com
Mon Apr 14 00:46:54 EDT 2003
[Jane Austine]
> ...
> For example,
>
> >>> class mydate(datetime.date):
> def abc(self):
> print "abc"
> >>> z=mydate(2003,4,14)
> >>> z.abc()
> Traceback (most recent call last):
> File "<pyshell#6>", line 1, in -toplevel-
> z.abc()
> AttributeError: 'datetime.date' object has no attribute 'abc'
> >>> type(z)
> <type 'datetime.date'>
>
> ...
>
> I reckon it is not subclassing the datetime.date class in
> its proper definition of subclassing.
Indeed it's not! That wasn't intended. I opened a bug report:
http://www.python.org/sf/720908
More information about the Python-list
mailing list