FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
Python's datetime Double Import Trap: 'type object datetime.datetime has no attribute datetime'
NewsProgramming Languages

Python's datetime Double Import Trap: 'type object datetime.datetime has no attribute datetime'

via Dev.to Pythonlinou5182h ago

While adding code to a Flask API server, I suddenly hit this error: AttributeError: type object 'datetime.datetime' has no attribute 'datetime' My code looked like this: datetime . datetime . now () Nothing obviously wrong. But Python said "no such attribute." What Was Happening The real issue was at the top of the file: import datetime from datetime import datetime These two lines coexist. Here's the problem: import datetime binds the module to the name datetime from datetime import datetime binds the class to the name datetime The second import overwrites the first. Now datetime refers to the class, not the module. When you call datetime.datetime.now() , Python looks for a datetime attribute on the datetime class — which doesn't exist. Hence the error. Why It's Easy to Miss When files grow long, you stop checking import lines. When copy-pasting code from other files, you bring imports along too. The collision stays hidden until runtime. In my case: original code used import datetime

Continue reading on Dev.to Python

Opens in a new tab

Read Full Article
0 views

Related Articles

The Math Behind a Realistic Metallic Border Effect in Flutter
News

The Math Behind a Realistic Metallic Border Effect in Flutter

Medium Programming • 46m ago

News

Slopification and its Discontents

Lobsters • 1h ago

Instruction Best Practices: Precision Beats Clarity
News

Instruction Best Practices: Precision Beats Clarity

Dev.to • 1h ago

Cauldron Ferm has turned microbes into nonstop assembly lines
News

Cauldron Ferm has turned microbes into nonstop assembly lines

TechCrunch • 1h ago

Zoox is bringing its robotaxis to Austin and Miami
News

Zoox is bringing its robotaxis to Austin and Miami

The Verge • 1h ago

Discover More Articles