Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64610
| Date | 2014-01-23 08:16 -0600 |
|---|---|
| Subject | datetime as subclass of date |
| From | Skip Montanaro <skip@pobox.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5892.1390486606.18130.python-list@python.org> (permalink) |
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
datetime as subclass of date Skip Montanaro <skip@pobox.com> - 2014-01-23 08:16 -0600
csiph-web