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


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

datetime as subclass of date

Started bySkip Montanaro <skip@pobox.com>
First post2014-01-23 08:16 -0600
Last post2014-01-23 08:16 -0600
Articles 1 — 1 participant

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


Contents

  datetime as subclass of date Skip Montanaro <skip@pobox.com> - 2014-01-23 08:16 -0600

#64610 — datetime as subclass of date

FromSkip Montanaro <skip@pobox.com>
Date2014-01-23 08:16 -0600
Subjectdatetime as subclass of date
Message-ID<mailman.5892.1390486606.18130.python-list@python.org>
This took my by surprise just now:

>>> import datetime
>>> now = datetime.datetime.now()
>>> isinstance(now, datetime.datetime)
True
>>> isinstance(now, datetime.time)
False
>>> isinstance(now, datetime.date)
True
>>> issubclass(datetime.datetime, datetime.date)
True

I'd never paid any attention to the relationship between the datetime,
time, and date classes of the datetime module before now, but have an
application where, for backwards compatibility, date objects must be
mapped to datetime objects with a time of midnight. That wasn't
working, because I was asking if a datetime instance was an instance
of a date. Which, it turns out, it is.

Skip

[toc] | [standalone]


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


csiph-web