sub-classing datetime

Discussion in 'Python' started by Colin J. Williams, Feb 7, 2013.

  1. 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.
    Colin J. Williams, Feb 7, 2013
    #1
    1. Advertising

  2. Colin J. Williams

    marduk Guest

    On Thu, Feb 7, 2013, at 10:13 AM, Colin J. Williams wrote:
    > 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).
    marduk, Feb 7, 2013
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pritam Kamat

    Obfuscation and sub classing

    Pritam Kamat, Aug 8, 2003, in forum: Java
    Replies:
    2
    Views:
    517
    pete kirkham
    Aug 8, 2003
  2. Colin J. Williams

    Sub-classing NumArray - two questions

    Colin J. Williams, Oct 1, 2003, in forum: Python
    Replies:
    0
    Views:
    265
    Colin J. Williams
    Oct 1, 2003
  3. Bernard Lebel

    Problem with sub-classing

    Bernard Lebel, Jul 17, 2006, in forum: Python
    Replies:
    3
    Views:
    359
    Peter Otten
    Jul 17, 2006
  4. Colin J. Williams
    Replies:
    1
    Views:
    258
    Michael Amrhein
    Aug 15, 2007
  5. Colin J. Williams
    Replies:
    5
    Views:
    309
    Colin J. Williams
    Aug 17, 2007
Loading...

Share This Page