New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add module level now() and today() functions to datetime module #53149
Comments
Current OOP API of datetime is ugly: from datetime import datetime
print datetime.today().isoformat() The proposal is to add today() and now() as module functions: from datetime import today, now
print today()
# datetime.date(2010, 6, 5)
print now()
# datetime.datetime(2010, 6, 5, 9, 48, 4, 868000) |
How hard is it to add now = datetime.now
todate = date.today at the top of your module is you really like shorter names? -1 |
Note that it is important to keep class methods because in some cases it is convenient to obtain now/today from datetime/date instances instead of importing them from the module. So deprecating class methods is not an option and adding module level functions that are equivalent to existing class methods is not TOOWTDI. |
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() I always have to remember that 'now' is a class method, often after getting a "datetime module has no attribute 'now'" message. In most standard library modules a function like that would be, well, a function. I can't imagine code where I'd find it more convenient to get 'now' from the class, and if I saw code like timestamp = othertimestamp.now() I'd run screaming. Personally I think the class methods would be better off deprecated in favor of module level functions. However, all that said, the datetime API is what it is, and I'm not sure it is worth going through a deprecation cycle for this. (Though othertimestamp.now() really does give me the heebie jeebies.) |
On Thu, Jun 10, 2010 at 10:37 PM, R. David Murray
Given the unfortunate name clash between the class and the module, I Also, ISTM that the datetime module was designed to allow easy ... pass
>>> Date.today()
Date(2010, 6, 10) Writing a separate module level today() for the subclass would be quite awkward. |
FWIW, I concur with the rejection. |
Raymond mention your reasons please. I may need them one day for describing development process. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: