Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38353 > unrolled thread

sub-classing datetime

Started by"Colin J. Williams" <cjw@ncf.ca>
First post2013-02-07 10:13 -0500
Last post2013-02-07 14:16 -0500
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  sub-classing datetime "Colin J. Williams" <cjw@ncf.ca> - 2013-02-07 10:13 -0500
    Re: sub-classing datetime marduk <marduk@python.net> - 2013-02-07 14:16 -0500

#38353 — sub-classing datetime

From"Colin J. Williams" <cjw@ncf.ca>
Date2013-02-07 10:13 -0500
Subjectsub-classing datetime
Message-ID<kf0gb1$dal$1@theodyn.ncf.ca>
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.

[toc] | [next] | [standalone]


#38360

Frommarduk <marduk@python.net>
Date2013-02-07 14:16 -0500
Message-ID<mailman.1456.1360264582.2939.python-list@python.org>
In reply to#38353

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).

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web