Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64610 > unrolled thread
| Started by | Skip Montanaro <skip@pobox.com> |
|---|---|
| First post | 2014-01-23 08:16 -0600 |
| Last post | 2014-01-23 08:16 -0600 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
datetime as subclass of date Skip Montanaro <skip@pobox.com> - 2014-01-23 08:16 -0600
| From | Skip Montanaro <skip@pobox.com> |
|---|---|
| Date | 2014-01-23 08:16 -0600 |
| Subject | datetime 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
Back to top | Article view | comp.lang.python
csiph-web