The Django book, Second Edition.
djangobook.com
djangobook.com
http://blog.clintecker.com/post/66123727/django-1-0-2-docume...
It comes down to how you import it. These two bits of code are equivalent:
# Example 1
import datetime; print datetime.datetime.now()
# Example 2
from datetime import datetime; print datetime.now()
I generally prefer "import FOO" over "from FOO import BAR", which is why you see example 1 used in the Django Book.
If the datetime module was written today, it would make a bit more sense looking like this:
import datetime
datetime.DateTime.now()
Anyway, since the common utilities in that are all attached to the datetime class in that module, there's no harm in importing the class directly. You could even fix the naming yourself, if you were so inclined:
from datetime import datetime as DateTime
DateTime.now()One of the nice things about Python is that you should be able to see where something comes from anytime you're using it. If you're referencing something, it will either be defined in that file or be defined by something imported at the top. So, if you see "Site.objects.get_current()" you can easily search the file for where Site comes from. Maybe it's a Site class defined in the file itself. Maybe it's imported from django.contrib.sites.models. Maybe it's from somewhere else. The nice thing is that you can easily see where it comes from so that you can look up that code.
This is very unlike many languages. PHP's include()/require() could execute anything when you call them and define any number of things and you might not know where they come from so easily. I get push back on this from some of my friends who argue that good IDEs should track that for you, but I like that there isn't the ambiguity in Python.