[issue8903] Add module level now() and today() functions to datetime module

Alexander Belopolsky report at bugs.python.org
Fri Jun 11 06:02:57 CEST 2010


Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

On Thu, Jun 10, 2010 at 10:37 PM, R. David Murray
<report at bugs.python.org> wrote:
>
> R. David Murray <rdmurray at bitdance.com> added the comment:
>
> I actually agree with Anatoly here.  I find it much more intuitive to do
>
>  import datetime
>
>   timestamp = datetime.now()
>
> than to do
>
>   timestamp = datetime.datetime.now()
>

Given the unfortunate name clash between the class and the module, I
never do "import datetime" and instead doe "from datetime import
datetime, date".  I find it very convenient  that importing datetime
class brings in all related functions and I don't need to import
factory functions separately.

Also, ISTM that the datetime module was designed to allow easy
extension by subclassing.  The factory methods are written so that
they work for subclasses:

...   pass
>>> Date.today()
Date(2010, 6, 10)

Writing a separate module level today() for the subclass would be quite awkward.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8903>
_______________________________________


More information about the Python-bugs-list mailing list