'Missing properties in python's datetime module

I came across datetime module in python, as this is first time i need it in my scripts.

But I really have a problem with it, in example:

import datetime

date_now = datetime.date.today()

print date_now

As an answer i get:

Traceback (most recent call last):

File "datetime.py", line 3, in

import datetime

File "/root/Desktop/python_work/datetime.py", line 5, in

today = datetime.date.today()

AttributeError: 'module' object has no attribute 'date'

Then i checked my datetime module to list properties:

import datetime

for p in dir(datetime):

    print p

As a result i got only:

> __builtins__
> 
> __doc__
> 
> __file__
> 
> __name__
> 
> __package__
> 
> datetime

And yeah, true, 'module' object has no attribute 'date', it really do not have it.

Is there any idea, what should be added to python install or how to fix it?



Solution 1:[1]

Rename your file from datetime.py" to something else. This name is conflicting with the builtin datetime module. Hence the error.

Solution 2:[2]

THANK YOU

IT

SOLVED

MY PROBLEM. I HAD A FILE NAMED datetime.py I changed it to dt((DATETIME)).py

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aryaveer
Solution 2 Remy Danon