Or it might have just been merged into the time module. The datetime module is mostly a single class which wraps the functions in the time module and adds a few convenience methods. I wouldn't be surprised if the reason for the separation is just historical -- say, time was written to match the C library, and later someone donated datetime as a set of utilities with an OO interface.
Anyway, since the common utilities in that are all attached to the datetime class in that module, there's no harm in importing the class directly. You could even fix the naming yourself, if you were so inclined:
from datetime import datetime as DateTime
DateTime.now()So a `DateTime = datetime' in the module would let newer code look more conventional?
Re:The Django book, Second Edition.
by EliAndrewC on Saturday January 10, 2009 @09:30PM
(#428692)
It would make the datetime class look more like other class names, but I'd strongly recommend against doing this. The Python community values consistency in the way that code is written (TOOWTDI) and this would be a sharp departure from that.
Fair, but maybe some class renames wouldn't be a bad idea for the v2 to v3 switch over. I don't know what the priorities are or what the bar is for changes that make the cut, so don't quote me on this :-)
If the datetime module was written today, it would make a bit more sense looking like this:
import datetime
datetime.DateTime.now()