I was playing with the dateutil
module in Python 2.7.3. I simply wanted to use:
import dateutil
dateutil.parser.parse("01-02-2013")
But I got an error:
AttributeError: 'module' object has no attribute 'parser'
I checked what attributes dateutil
does have:
print dir(dateutil)
# output: ['__author__', '__builtins__', '__doc__', '__file__', '__license__',
# '__name__', '__package__', '__path__', '__version__']
The thing is, when I try to import parser
from dateutil
directly, it does seem to exist:
from dateutil import parser
print parser.parse("01-02-2013")
# output: 2013-01-02 00:00:00
After the from dateutil import parser
, parser
has also magically appeared in the imported dateutil
itself:
print dir(dateutil)
# output: ['__author__', '__builtins__', '__doc__', '__file__', '__license__',
# '__name__', '__package__', '__path__', '__version__', 'parser',
# 'relativedelta', 'tz']
Note that some other attributes (like rrule
) are still missing from this list.
Anyone knows what's going on?
datetime.date.today()
, I would firstimport datetime
, and thenprint datetime.date.today()
. Is there a reason this wouldn't work fordateutil
? – Hardecanute