News for hackers. Stuff that matters.
Re:The Django book, Second Edition. by mdasen on Friday January 09, 2009 @06:48PM (#427324)
Basically, what it comes down to is Python's explicit over implicit policy. First, unlike PHP, not everything in the Python language is automatically included in every file. You explicitly import things. datetime is a module in the standard Python library. It includes several things: datetime, time, date, timedelta. . . So, often what you want is a datetime object from the datetime module, but you could do datetime.date.today().

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.

Re:The Django book, Second Edition. by bdr on Saturday January 10, 2009 @12:09AM (#427650)
To be fair, an import in Python could execute anything, too.
Re:The Django book, Second Edition. by newt0311 on Saturday January 10, 2009 @12:40AM (#427685)
True. It would be much nicer to have a now method in the datetime module so that we could just do import datetime; now = datetime.now()