Attribute Error: ‘type’ object has no attribute ‘datetime’

While trying to write some test for NTP servers, my response time used this:
I am using IronPython 2.7.

timetoreturn = time.time()            
if(self.response_time != 0):                
timetoreturn = (self.response_time – datetime.datetime(1970,1,1)).total_seconds()

I got this error: Attribute Error: ‘type’ object has no attribute ‘datetime’.

My imports were:
import datetime
from datetime import datetime, tzinfo

Come to find out, using import datetime just causes problems so I removed that. That left me with ‘from datetime import datetime, tzinfo’.

Now. What the heck is the deal?

This is what. Datetime module has an object named datetime that you can use. Which is very confusing. So FROM DATETIME means that I am in the datetime module, importing datetime object to use, and from there I can just use the attributes. Instead, I was writing ‘datetime.datetime’ meaning I was already in the second level of inception (datetime > datetime) and then trying to access an attribute named ‘datetime’. So datetime.datetime.datetime.

This doesn’t work. 🙂

Just be aware of the level of the module you are in when importing and accessing attributes.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s