def get_as_dtype(self, section, option, dtype, default=None): """Convenience method to query options with a custom default and type This method simply wraps the base class method, but adds a `default` keyword argument. The value of `default` is returned whenever the config parser does not have the requested option and/or section. In addition, the returned value is converted into the specified `dtype`. """ if not self.has_option(section, option): return default try: return SafeConfigParser._get(self, section, dtype, option) except ValueError as e: # provide somewhat descriptive error raise ValueError("Failed to obtain value from configuration for %s.%s. " \ "Original exception was: %s" % (section, option, e))