Subclassing: what is wrong here?

P

Paulo da Silva

Hi!

What's wrong with this way of subclassing?

from datetime import date

class MyDate(date):
def __init__(self,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
date.__init__(self,year,month,day)

When I do
d=MyDate("2007-3-15")
I got
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: function takes exactly 3 arguments (1 given)

Thanks for any help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,172
Latest member
NFTPRrAgenncy
Top