Why "flat is better than nested"?
Albert Hopkins
marduk at letterboxes.org
Tue Oct 26 13:52:31 EDT 2010
On Tue, 2010-10-26 at 09:45 -0700, John Nagle wrote:
> On 10/25/2010 6:34 AM, Alex Willmer wrote:
> > On Oct 25, 11:07 am, kj<no.em... at please.post> wrote:
> >> In "The Zen of Python", one of the "maxims" is "flat is better than
> >> nested"? Why? Can anyone give me a concrete example that illustrates
> >> this point?
> >
> > I take this as a reference to the layout of the Python standard
> > library and other packages i.e. it's better to have a module hierarchy
> > of depth 1 or 2 and many top level items, than a depth of 5+ and only
> > a few top level items.
> >
> > For instance
> >
> > import re2
> > import sqlite3
> > import logging
> >
> > import something_thirdparty
> >
> > vs
> >
> > import java.util.regex
> > import java.sql
> > import java.util.logging
>
> As in
>
> Python 2: import urllib
> Python 3: import urllib.request, urllib.parse, urllib.error
>
> http://diveintopython3.org/porting-code-to-python-3-with-2to3.html
>
My favorite is always:
from django.contrib.auth.models import User # I know, not std lib
More information about the Python-list
mailing list