Friday Filosofical Finking: Import protections

DL Neil PythonList at DancesWithMice.info
Wed Apr 17 23:54:55 EDT 2019


On 18/04/19 8:53 AM, Larry Martell wrote:
> On 2019-04-17 21:20, DL Neil wrote:
>> Do you bother with exception handling for import statements?
> 
> I often have to do something like this:
> 
> try:
>      from settings import SITE_WAFER_DIAMETER
> except ImportError:
>      SITE_WAFER_DIAMETER = 300


That's an interesting application. Most of the multiple input 
configuration options examples (I've seen) start with a base of the 
least-prioritised values, and then 'add' higher-priority configuration 
option-values to that.

In this case we: import the config file, but if it's not available use 
the stated fall-back value(s).

Good one!
-- 
Regards =dn



More information about the Python-list mailing list