sub-classing datetime

  • Thread starter Colin J. Williams
  • Start date
C

Colin J. Williams

I'm just making the transition from 2 to 3 for one module.

With Python 2.7, I had the benefit of mx datetime, but this is not yet
available for Python 3.2.

I find that the 3.2 datetime is not subclassable, for reasons that were
known some years back.

It would help if there was a note in the docs listing the builtin
classes which are not subclassable.

I am retreating to the use of a function.

Any other suggestions?

Colin W.
 
M

marduk

I'm just making the transition from 2 to 3 for one module.

With Python 2.7, I had the benefit of mx datetime, but this is not yet
available for Python 3.2.

I find that the 3.2 datetime is not subclassable, for reasons that were
known some years back.

It would help if there was a note in the docs listing the builtin
classes which are not subclassable.

I am retreating to the use of a function.

What makes you think it's not subclassable?:

import datetime

class MyDateTime(datetime.datetime):
def what_date(self):
print(self)


md = MyDateTime.now()
md.what_date()

Seems to work even in 2.7 (excluding the print function).
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top