python - Default settings for application -


i know settingslogic-gem ruby. allows elegant way define default settings or fallback-settings application described in settingslogic example.

i'm reading through pyyaml didn't find yet such nice way this.

how solve such problem in elegant , pythonic way?

i'm not sure why expect yaml-parsing library provide multi-layered settings fallback. ruby's yaml-parsing library doesn't, why there separate wrapper gems 1 referred in first place.

but if @ linked to, there isn't logic in library @ all; application logic code has use ||= set value if it's missing. can same thing in python; it's spelled different.

in ruby, use dot-access if want exception on missing key, brackets if want nil, brackets plus || if want different default value, , hacky idiomatic brackets plus ||= if want set , return different default value.

in python, use brackets if want exception on missing key, get if want none, get argument want different default, , setdefault if want set , return different default. so, ruby code:

>> settings.messaging['queue_name'] ||= 'user_mail' => "user_mail" 

… looks in python:

>>> settings['messaging'].setdefault('queue_name', 'user_mail') user_mail 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

visual studio - TFS will not accept changes I've made to a Java project -