News for hackers. Stuff that matters.
Re:Stop writing classes... by astrofinch on Saturday March 17, 2012 @06:06PM (#3718373)
Why are you masking errors from that import?
Re:Stop writing classes... by tawhaki on Saturday March 17, 2012 @06:22PM (#3718400)
I assume it is so that the default values are used if no local_settings.py file exists, instead of aborting the program with an uncaught ImportError.
Re:Stop writing classes... by pjscott on Saturday March 17, 2012 @09:01PM (#3718739)
If so, then for the benefit of any Python newbies here: "except ImportError" is the idiomatic way to handle this situation, it it clearly communicates intent, and prevents masking legitimate errors. One fairly common pattern is to try to import one module, and if it's not installed, to go for a backup. For example, if I need to parse JSON, the simplejson library is significantly faster than the (completely API-compatible) standard library "json" module:

    try:
        import simplejson as json
    except ImportError:
        import json
I'm pretty sure I've seen those exact four lines of code in the internals of Tornado and Flask, among others.
Re:Stop writing classes... by mdonahoe on Saturday March 17, 2012 @09:58PM (#3718868)
explicit is better than implicit

He should explicitly catch the ImportError