當前位置: 首頁>>代碼示例>>Python>>正文


Python locale.atof方法代碼示例

本文整理匯總了Python中locale.atof方法的典型用法代碼示例。如果您正苦於以下問題:Python locale.atof方法的具體用法?Python locale.atof怎麽用?Python locale.atof使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在locale的用法示例。


在下文中一共展示了locale.atof方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: numberFromString

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import atof [as 別名]
def numberFromString(self, string):
        # Uses the current system locale, irrespective of language choice.
        # Returns None if the string is not parsable, otherwise an integer or float.
        if platform=='darwin':
            return self.float_formatter.numberFromString_(string)
        else:
            try:
                return locale.atoi(string)
            except:
                try:
                    return locale.atof(string)
                except:
                    return None

    # Returns list of preferred language codes in RFC4646 format i.e. "lang[-script][-region]"
    # Where lang is a lowercase 2 alpha ISO 639-1 or 3 alpha ISO 639-2 code,
    # script is a capitalized 4 alpha ISO 15924 code and region is an uppercase 2 alpha ISO 3166 code 
開發者ID:EDCD,項目名稱:EDMarketConnector,代碼行數:19,代碼來源:l10n.py

示例2: float

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import atof [as 別名]
def float(self, val):
        """
        Parse a string to a floating point number. Uses locale.atof(),
        in future with ICU present will use icu.NumberFormat.parse().
        """
        try:
            return locale.atof(val)
        except ValueError:
            point = locale.localeconv()['decimal_point']
            sep = locale.localeconv()['thousands_sep']
            try:
                if point == ',':
                    return locale.atof(val.replace(' ', sep).replace('.', sep))
                elif point == '.':
                    return locale.atof(val.replace(' ', sep).replace(',', sep))
                else:
                    return None
            except ValueError:
                return None

#-------------------------------------------------------------------------
#
# Translations Classes
#
#------------------------------------------------------------------------- 
開發者ID:GenealogyCollective,項目名稱:gprime,代碼行數:27,代碼來源:locale.py

示例3: _response_hook

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import atof [as 別名]
def _response_hook(self, r: requests.Response, *args, **kwargs):
        """This method always exists as a response hook in order to keep some of the state returned by the
        DEP service internally such as:
            - The last value of the `X-ADM-Auth-Session` header, which is used on subsequent requests.
            - The last value of the `Retry-After` header, which is used to set an instance variable to indicate
                when we may make another request.

        See Also:
            - `Footnote about **X-ADM-Auth-Session** under Response Payload <https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/MobileDeviceManagementProtocolRef/4-Profile_Management/ProfileManagement.html#//apple_ref/doc/uid/TP40017387-CH7-SW2>`_.
        """
        if r.status_code == 401:  # Token may be expired, or token is invalid
            pass  # TODO: Need token refresh as decorator

        # If the service gives us another session token, that replaces our current token.
        if 'X-ADM-Auth-Session' in r.headers:
            self._session_token = r.headers['X-ADM-Auth-Session']

        # If the service wants to rate limit us, store that information locally.
        if 'Retry-After' in r.headers:
            after = r.headers['Retry-After']
            if re.compile(r"/[0-9]+/").match(after):
                d = timedelta(seconds=atof(after))
                self._retry_after = datetime.utcnow() + d
            else:  # HTTP Date
                self._retry_after = datetime(*parsedate(after)[:6]) 
開發者ID:cmdmnt,項目名稱:commandment,代碼行數:27,代碼來源:dep.py

示例4: is_number

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import atof [as 別名]
def is_number(s):
    try:
        locale.atof(s)
        return True
    except ValueError:
        pass
    # put string like '3\/32' into numbers
    try:
        special_str = '\/'
        pos = s.find(special_str)
        if pos > 0:
            locale.atoi(s[:pos])
            locale.atoi(s[pos+len(special_str):])
            return True
    except ValueError:
        pass
    return False 
開發者ID:RemiLeblond,項目名稱:SeaRNN-open,代碼行數:19,代碼來源:conll.py

示例5: cast

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import atof [as 別名]
def cast(self, value):
        try:
            return decimal.Decimal(value)
        except:
            value = locale.atof(value)
            if sys.version_info < (2, 7):
                value = str(value)
            return decimal.Decimal(value) 
開發者ID:MacroConnections,項目名稱:DIVE-backend,代碼行數:10,代碼來源:type_classes.py

示例6: cast

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import atof [as 別名]
def cast(self, value):
        if value in ('', None):
            return None
        try:
            return decimal.Decimal(value)
        except:
            value = locale.atof(value)
            if sys.version_info < (2, 7):
                value = str(value)
            return decimal.Decimal(value) 
開發者ID:MacroConnections,項目名稱:DIVE-backend,代碼行數:12,代碼來源:types.py

示例7: _test_atof

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import atof [as 別名]
def _test_atof(self, value, out):
        self.assertEqual(locale.atof(value), out) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:4,代碼來源:test_locale.py

示例8: parse_real

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import atof [as 別名]
def parse_real(question, value):
        try:
            # Use a locale to parse human input since it may have
            # e.g. thousands-commas. The locale is set on app
            # startup using locale.setlocale in settings.py.
            import locale
            return locale.atof(value)
        except ValueError:
            # make a nicer error message
            raise ValueError("Invalid input. Must be a number.") 
開發者ID:GovReady,項目名稱:govready-q,代碼行數:12,代碼來源:answer_validation.py

示例9: FloatFromString

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import atof [as 別名]
def FloatFromString(str_value, use_locale=True):
    """
    Converts the given string value into a float, taking in account the current locale.

    :param str str_value:

    :rtype: float
    :returns:
        The equivalent float value

    :param bool use_locale:
        Use locale.atof or standard float conversion (default python output, locale-independent).

    :raises ValueError:
        If given string is not a valid float literal in the current locale
    """
    import locale

    if str_value.__class__ != str:
        from barril._util.types_ import CheckType

        CheckType(str_value, str)

    if str_value == PLUS_INFINITY_STR:
        return PLUS_INFINITY
    elif str_value == MINUS_INFINITY_STR:
        return MINUS_INFINITY
    elif str_value == NAN_STR:
        return NAN
    elif use_locale:
        return locale.atof(str_value)
    else:
        return float(str_value) 
開發者ID:ESSS,項目名稱:barril,代碼行數:35,代碼來源:__init__.py


注:本文中的locale.atof方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。