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


Groups > comp.lang.python > #38360

Re: sub-classing datetime

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <marduk@python.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'builtin': 0.07; 'python': 0.09; 'received:internal': 0.09; 'def': 0.10; '2.7': 0.13; '(excluding': 0.16; '10:13': 0.16; '3.2.': 0.16; 'function).': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:mail.srv.osa': 0.16; 'received:messagingengine.com': 0.16; 'received:nyi.mail.srv.osa': 0.16; 'received:osa': 0.16; 'received:srv.osa': 0.16; 'subject:sub': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'feb': 0.19; 'import': 0.21; '3.2': 0.22; 'back.': 0.22; 'seems': 0.23; 'header:In-Reply-To:1': 0.25; 'skip:m 30': 0.26; 'am,': 0.27; 'module.': 0.27; 'transition': 0.27; 'class': 0.29; "i'm": 0.29; 'classes': 0.30; 'print': 0.32; 'docs': 0.33; 'function.': 0.33; 'to:addr:python-list': 0.33; 'there': 0.35; 'but': 0.36; 'listing': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'received:10': 0.38; 'to:addr:python.org': 0.39; 'subject:-': 0.40; 'header:Received:5': 0.40; 'help': 0.40; 'think': 0.40; 'header:Message-Id:1': 0.62; 'making': 0.64; 'benefit': 0.70
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:in-reply-to:references :subject:date; s=smtpout; bh=D5TkKJe8xEa/ZOkHU1juKUClkUI=; b=Vq8 JdCX/Olsst7mN0jodmriC2l6SMk2fD2DvAOPq1/BcF194f6uf0edH1nke+y6z7/2 r4Hzh2aiJUTGGzlTESsbpbL+YcHb27HiSd3WK7t54zyRO7NU9edORySHpO8wM/tW eVWM1vehkvbA4uNodl8LgNKhjiyP4K7j95CR+RZs=
X-Sasl-Enc Um7wxG6DXoac6XSW3UO8KqJGSlxOaIPgIH7aJaWjYsZD 1360264574
From marduk <marduk@python.net>
To python-list@python.org
MIME-Version 1.0
Content-Transfer-Encoding 7bit
Content-Type text/plain
X-Mailer MessagingEngine.com Webmail Interface - ajax-bcb164fb
In-Reply-To <kf0gb1$dal$1@theodyn.ncf.ca>
References <kf0gb1$dal$1@theodyn.ncf.ca>
Subject Re: sub-classing datetime
Date Thu, 07 Feb 2013 14:16:14 -0500
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1456.1360264582.2939.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360264582 news.xs4all.nl 6913 [2001:888:2000:d::a6]:49011
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38360

Show key headers only | View raw



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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

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

csiph-web