User’s own custom datetime.py module was overriding standard library, the information below is still useful to understand why that would happen. The import algorithm first checks your immediate directory. You can check that modules file path with:
print a_module.__file__
Welcome to the wild world of programming. So, I’m not sure I fully understand your question, so I will try to break some things down and leave room for you to discuss.
When you import datetime you import whats called a module. Without going into to much detail modules are what are commonly known as namespaces, they serve to create separation of attributes under a hierarchy so you dont accidentally overwrite other code on import. You can read more read about it here:
The datetime module supplies classes for manipulating dates and times
in both simple and complex ways. While date and time arithmetic is
supported, the focus of the implementation is on efficient attribute
extraction for output formatting and manipulation. For related
functionality, see also the time and calendar modules.
When you import it and run the type method on it you should see the following results:
>>> import datetime
>>> type(datetime)
<class 'module'>
The builtin type method documentation states the following:
4.12.6. Type Objects
Type objects represent the various object types. An object’s type is accessed by the built-in function type(). There are no special operations on types. The standard module types defines names for all standard built-in types.
When you explicitly print that output it will be the same result:
>>> print(type(datetime))
<class 'module'>
Modules expose attributes on import. The attribute you are accessing is the datetime modules datetime attribute which is a class that happens to just have the same name. So when you access it looks like datetime.datetime
That class supports a method (which is also an attribute of the class, not the module) named “now”. So, when you are accessing that method it looks like datetime.datetime.now() to call it.
If you wanted to simplify this heirarchy on import you could clarify that you only want the datetime class out of the datetime module:
from datetime import datetime
#and the access its now method simpler
d1 = datetime.now()
This may help with the attribute access problems, it may be a matter of confusion. If you want to clarify your problem more, please feel free to do so!