Subclassing: what is wrong here?
Paulo da Silva
psdasilvaX at esotericaX.ptX
Thu Mar 15 23:18:24 EDT 2007
Miki escreveu:
> Hello Paulo,
>
>> What's wrong with this way of subclassing?
>> ...
> See http://sourceforge.net/tracker/index.php?func=detail&aid=1448640&group_id=5470&atid=105470
>
> HTH,
> --
> Miki <miki.tebeka at gmail.com>
> http://pythonwise.blogspot.com
>
Thanks!
It works this way:
class MyDate(date):
def __new__(cls,year,month=None,day=None):
if type(year) is str:
# The whole date is here as a string
year,month,day=map(int,string.split(year,'-'))
if year<100:
year+=2000
return date.__new__(cls,year,month,day)
More information about the Python-list
mailing list