Created
November 3, 2013 16:59
-
-
Save pierreozoux/7292309 to your computer and use it in GitHub Desktop.
Python...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ✘ pierreozoux@local ⮀ ~ ⮀ python | |
| Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) | |
| [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin | |
| Type "help", "copyright", "credits" or "license" for more information. | |
| >>> import datetime | |
| >>> datetime.today() | |
| Traceback (most recent call last): | |
| File "<stdin>", line 1, in <module> | |
| AttributeError: 'module' object has no attribute 'today' | |
| >>> from datetime import datetime | |
| >>> datetime.today() | |
| datetime.datetime(2013, 11, 3, 16, 45, 50, 745661) | |
| >>> datetime.timedelta(days=30) | |
| Traceback (most recent call last): | |
| File "<stdin>", line 1, in <module> | |
| AttributeError: type object 'datetime.datetime' has no attribute 'timedelta' | |
| >>> import datetime | |
| >>> datetime.timedelta(days=30) | |
| datetime.timedelta(30) | |
| >>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I agree this is confusing. The
datetime.datetimeis a class which has bunch of useful classmethods (likenow). I usually dofrom datetime import datetime, timedeltaand then your code will look good. If you need to access the datetime module (rather than thedatetime.datetimeclass), you can access it with:sys.modules['datetime'].