changeset 383:5c72da46b8ae

Implemented Configuration.getfirstfloatvar_s(). This was missing.
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 10 Nov 2021 01:53:23 +0100
parents 24db29162d09
children 8c3aaa894089
files CHANGES.txt configmix/config.py
diffstat 2 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Wed Nov 10 01:42:15 2021 +0100
+++ b/CHANGES.txt	Wed Nov 10 01:53:23 2021 +0100
@@ -19,6 +19,9 @@
   :py:meth:`~configmix.config.Configuration.getfirstvarl`,
   :py:meth:`~configmix.config.Configuration.getfirstvarl_s`
 
+- **[feature]** New access method
+  py:meth:`~configmix.config.Configuration.getfirstfloatvar_s`
+
 
 0.16 (2021-07-11)
 ~~~~~~~~~~~~~~~~~
--- a/configmix/config.py	Wed Nov 10 01:42:15 2021 +0100
+++ b/configmix/config.py	Wed Nov 10 01:53:23 2021 +0100
@@ -367,6 +367,17 @@
         else:
             return s
 
+    def getfirstfloatvar_s(self, varname, default=_MARKER):
+        """Get a (possibly substituted) variable and convert text to a
+        float
+
+        """
+        s = self.getfirstvar_s(varname, default)
+        if isinstance(s, self._TEXTTYPE):
+            return float(s)
+        else:
+            return s
+
     def _split_ns(self, s):
         nameparts = s.split(self._NS_SEPARATOR, 1)
         if len(nameparts) == 1: