472,145 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

sub-classing the types in the builtin module datetime

I wish to sub-class (if that's the right word) datetime and to use a
different signature for the constructor.

The second part has gone smoothly, but it is difficult to access the
type's methods from the sub-class instance.

I'm beginning to wonder whether it might might be simpler to write my
own Date class.

Does anyone have any comments please?

Colin W.

Aug 15 '07 #1
1 1019
Colin J. Williams wrote:
I wish to sub-class (if that's the right word) datetime and to use a
different signature for the constructor.

The second part has gone smoothly, but it is difficult to access the
type's methods from the sub-class instance.
What's difficult?
>>from datetime import datetime
class mydt(datetime): pass
....
>>dt=mydt(2007,8,15)
dt.day
15
>>dt.now()
mydt(2007, 8, 15, 18, 57, 58, 562000)

How did you overwrite the constuctor?
Are you sure your constructor really returns a subclass of datetime?
I'm beginning to wonder whether it might might be simpler to write my
own Date class.
If you only want to change the signature of the constuctor, just write a
factory function.
Does anyone have any comments please?

Colin W.
Have fun,
Michael
Aug 15 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by John Dewbert | last post: by
3 posts views Thread by Kathy Burke | last post: by
6 posts views Thread by Thom Little | last post: by
reply views Thread by Saiars | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.