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


Python locale.localeconv方法代碼示例

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


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

示例1: DoCreateResource

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [as 別名]
def DoCreateResource(self):
        integerWidth = int(self.GetParamValue('integerwidth')) if self.HasParam('integerwidth') else 4
        fractionWidth = int(self.GetParamValue('fractionwidth')) if self.HasParam('fractionwidth') else 3

        ctrl = masked.NumCtrl(
                self.GetParentAsWindow(),
                self.GetID(),
                allowNegative=False,
                integerWidth=integerWidth,
                fractionWidth=fractionWidth,
                groupChar=' ',
                allowNone=False,
                decimalChar=locale.localeconv()['decimal_point'])
        self.SetupWindow(ctrl)
        self.CreateChildren(ctrl)

        return ctrl 
開發者ID:EarToEarOak,項目名稱:RF-Monitor,代碼行數:19,代碼來源:xrchandlers.py

示例2: test_float_with_comma

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [as 別名]
def test_float_with_comma(self):
        # set locale to something that doesn't use '.' for the decimal point
        # float must not accept the locale specific decimal point but
        # it still has to accept the normal python syntax
        import locale
        if not locale.localeconv()['decimal_point'] == ',':
            self.skipTest('decimal_point is not ","')

        self.assertEqual(float("  3.14  "), 3.14)
        self.assertEqual(float("+3.14  "), 3.14)
        self.assertEqual(float("-3.14  "), -3.14)
        self.assertEqual(float(".14  "), .14)
        self.assertEqual(float("3.  "), 3.0)
        self.assertEqual(float("3.e3  "), 3000.0)
        self.assertEqual(float("3.2e3  "), 3200.0)
        self.assertEqual(float("2.5e-1  "), 0.25)
        self.assertEqual(float("5e-1"), 0.5)
        self.assertRaises(ValueError, float, "  3,14  ")
        self.assertRaises(ValueError, float, "  +3,14  ")
        self.assertRaises(ValueError, float, "  -3,14  ")
        self.assertRaises(ValueError, float, "  0x3.1  ")
        self.assertRaises(ValueError, float, "  -0x3.p-1  ")
        self.assertRaises(ValueError, float, "  +0x3.p-1  ")
        self.assertEqual(float("  25.e-1  "), 2.5)
        self.assertEqual(test_support.fcmp(float("  .25e-1  "), .025), 0) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:test_float.py

示例3: _currency_symbols

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [as 別名]
def _currency_symbols():
    """Compile a list of valid currency symbols."""
    current = locale.getlocale()
    locales = list(locale.locale_alias.values())
    symbols = set()

    for loc in locales:
        try:
            locale.setlocale(locale.LC_MONETARY, locale.normalize(loc))
            currency = "{int_curr_symbol}".format(**locale.localeconv())
            if currency != "":
                symbols.add(currency.strip())
        except (locale.Error, UnicodeDecodeError):
            continue

    locale.setlocale(locale.LC_MONETARY, current)
    return list(symbols) 
開發者ID:project-koku,項目名稱:koku,代碼行數:19,代碼來源:serializers.py

示例4: test_float_with_comma

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [as 別名]
def test_float_with_comma(self):
        # set locale to something that doesn't use '.' for the decimal point
        # float must not accept the locale specific decimal point but
        # it still has to accept the normal python syntax
        import locale
        if not locale.localeconv()['decimal_point'] == ',':
            return

        self.assertEqual(float("  3.14  "), 3.14)
        self.assertEqual(float("+3.14  "), 3.14)
        self.assertEqual(float("-3.14  "), -3.14)
        self.assertEqual(float(".14  "), .14)
        self.assertEqual(float("3.  "), 3.0)
        self.assertEqual(float("3.e3  "), 3000.0)
        self.assertEqual(float("3.2e3  "), 3200.0)
        self.assertEqual(float("2.5e-1  "), 0.25)
        self.assertEqual(float("5e-1"), 0.5)
        self.assertRaises(ValueError, float, "  3,14  ")
        self.assertRaises(ValueError, float, "  +3,14  ")
        self.assertRaises(ValueError, float, "  -3,14  ")
        self.assertRaises(ValueError, float, "  0x3.1  ")
        self.assertRaises(ValueError, float, "  -0x3.p-1  ")
        self.assertRaises(ValueError, float, "  +0x3.p-1  ")
        self.assertEqual(float("  25.e-1  "), 2.5)
        self.assertEqual(test_support.fcmp(float("  .25e-1  "), .025), 0) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:27,代碼來源:test_float.py

示例5: float

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [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

示例6: test_float_with_comma

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [as 別名]
def test_float_with_comma(self):
        # set locale to something that doesn't use '.' for the decimal point
        # float must not accept the locale specific decimal point but
        # it still has to accept the normal python syntax
        import locale
        if not locale.localeconv()['decimal_point'] == ',':
            self.skipTest('decimal_point is not ","')

        self.assertEqual(float("  3.14  "), 3.14)
        self.assertEqual(float("+3.14  "), 3.14)
        self.assertEqual(float("-3.14  "), -3.14)
        self.assertEqual(float(".14  "), .14)
        self.assertEqual(float("3.  "), 3.0)
        self.assertEqual(float("3.e3  "), 3000.0)
        self.assertEqual(float("3.2e3  "), 3200.0)
        self.assertEqual(float("2.5e-1  "), 0.25)
        self.assertEqual(float("5e-1"), 0.5)
        self.assertRaises(ValueError, float, "  3,14  ")
        self.assertRaises(ValueError, float, "  +3,14  ")
        self.assertRaises(ValueError, float, "  -3,14  ")
        self.assertRaises(ValueError, float, "  0x3.1  ")
        self.assertRaises(ValueError, float, "  -0x3.p-1  ")
        self.assertRaises(ValueError, float, "  +0x3.p-1  ")
        self.assertEqual(float("  25.e-1  "), 2.5)
        self.assertAlmostEqual(float("  .25e-1  "), .025) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:27,代碼來源:test_float.py

示例7: test_locale

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [as 別名]
def test_locale(self):
        try:
            oldloc = locale.setlocale(locale.LC_ALL)
            locale.setlocale(locale.LC_ALL, '')
        except locale.Error as err:
            self.skipTest("Cannot set locale: {}".format(err))
        try:
            localeconv = locale.localeconv()
            sep = localeconv['thousands_sep']
            point = localeconv['decimal_point']

            text = format(123456789, "n")
            self.assertIn(sep, text)
            self.assertEqual(text.replace(sep, ''), '123456789')

            text = format(1234.5, "n")
            self.assertIn(sep, text)
            self.assertIn(point, text)
            self.assertEqual(text.replace(sep, ''), '1234' + point + '5')
        finally:
            locale.setlocale(locale.LC_ALL, oldloc) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:23,代碼來源:test_format.py

示例8: test_wide_char_separator_decimal_point

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [as 別名]
def test_wide_char_separator_decimal_point(self):
        # locale with wide char separator and decimal point
        import locale
        Decimal = self.decimal.Decimal

        decimal_point = locale.localeconv()['decimal_point']
        thousands_sep = locale.localeconv()['thousands_sep']
        if decimal_point != '\u066b':
            self.skipTest('inappropriate decimal point separator'
                          '({!a} not {!a})'.format(decimal_point, '\u066b'))
        if thousands_sep != '\u066c':
            self.skipTest('inappropriate thousands separator'
                          '({!a} not {!a})'.format(thousands_sep, '\u066c'))

        self.assertEqual(format(Decimal('100000000.123'), 'n'),
                         '100\u066c000\u066c000\u066b123') 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:18,代碼來源:test_decimal.py

示例9: format_satoshis

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [as 別名]
def format_satoshis(x, is_diff=False, num_zeros = 0, decimal_point = 8, whitespaces=False):
    from locale import localeconv
    if x is None:
        return 'unknown'
    x = int(x)  # Some callers pass Decimal
    scale_factor = pow (10, decimal_point)
    integer_part = "{:n}".format(int(abs(x) / scale_factor))
    if x < 0:
        integer_part = '-' + integer_part
    elif is_diff:
        integer_part = '+' + integer_part
    dp = localeconv()['decimal_point']
    fract_part = ("{:0" + str(decimal_point) + "}").format(abs(x) % scale_factor)
    fract_part = fract_part.rstrip('0')
    if len(fract_part) < num_zeros:
        fract_part += "0" * (num_zeros - len(fract_part))
    result = integer_part + dp + fract_part
    if whitespaces:
        result += " " * (decimal_point - len(fract_part))
        result = " " * (15 - len(result)) + result
    return result 
開發者ID:achow101,項目名稱:payment-proto-interface,代碼行數:23,代碼來源:util.py

示例10: format_satoshis

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [as 別名]
def format_satoshis(x, is_diff=False, num_zeros=0, decimal_point=8, whitespaces=False):
    from locale import localeconv
    if x is None:
        return 'unknown'
    x = int(x)  # Some callers pass Decimal
    scale_factor = pow(10, decimal_point)
    integer_part = "{:n}".format(int(abs(x) / scale_factor))
    if x < 0:
        integer_part = '-' + integer_part
    elif is_diff:
        integer_part = '+' + integer_part
    dp = localeconv()['decimal_point']
    fract_part = ("{:0" + str(decimal_point) + "}").format(abs(x) % scale_factor)
    fract_part = fract_part.rstrip('0')
    if len(fract_part) < num_zeros:
        fract_part += "0" * (num_zeros - len(fract_part))
    result = integer_part + dp + fract_part
    if whitespaces:
        result += " " * (decimal_point - len(fract_part))
        result = " " * (15 - len(result)) + result
    return result.decode('utf8') 
開發者ID:UlordChain,項目名稱:Uwallet,代碼行數:23,代碼來源:util.py

示例11: setUp

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [as 別名]
def setUp(self):
        self.sep = locale.localeconv()['thousands_sep'] 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:4,代碼來源:test_locale.py

示例12: test_wide_char_separator_decimal_point

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [as 別名]
def test_wide_char_separator_decimal_point(self):
        # locale with wide char separator and decimal point
        import locale

        decimal_point = locale.localeconv()['decimal_point']
        thousands_sep = locale.localeconv()['thousands_sep']
        if decimal_point != '\xd9\xab':
            self.skipTest('inappropriate decimal point separator '
                          '({!r} not {!r})'.format(decimal_point, '\xd9\xab'))
        if thousands_sep != '\xd9\xac':
            self.skipTest('inappropriate thousands separator '
                          '({!r} not {!r})'.format(thousands_sep, '\xd9\xac'))

        self.assertEqual(format(Decimal('100000000.123'), 'n'),
                         '100\xd9\xac000\xd9\xac000\xd9\xab123') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:17,代碼來源:test_decimal.py

示例13: run_regex_extraction

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [as 別名]
def run_regex_extraction(sample_text_str):

    # symbol usage:

    # locales=('en_AG', 'en_AU.utf8', 'en_BW.utf8', 'en_CA.utf8',
    #     'en_DK.utf8', 'en_GB.utf8', 'en_HK.utf8', 'en_IE.utf8', 'en_IN', 'en_NG',
    #     'en_NZ.utf8', 'en_PH.utf8', 'en_SG.utf8', 'en_US.utf8', 'en_ZA.utf8',
    #     'en_ZW.utf8')
    locales =('en_AG', 'en_AU.utf8', 'en_CA.utf8',
              'en_HK.utf8',
              'en_NZ.utf8', 'en_SG.utf8', 'en_US.utf8',
              'en_ZW.utf8')

    # for l in locales:
    #     locale.setlocale(locale.LC_ALL, l)
    #     conv=locale.localeconv()

    # print('{int_curr_symbol} ==> {currency_symbol}'.format(**conv))

    #     char_curr_sequence = conv['int_curr_symbol']
    #     currency_symbol = conv['currency_symbol']
    #
    #     print char_curr_sequence
    #     symbol = '$'
    #     trans_amount_l = scan_str_for_currency_symbols(symbol, sample_text_str)
    #     print trans_amount_l
    #
    # print sample_text_str

    symbol = '$'
    trans_amount_l = scan_str_for_currency_symbols(symbol, sample_text_str)
    print trans_amount_l
    return trans_amount_l

# Currently working regex (without spaces between $ and digits): 
開發者ID:Sotera,項目名稱:pst-extraction,代碼行數:37,代碼來源:extract_transaction.py

示例14: _formatSciNotation

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import localeconv [as 別名]
def _formatSciNotation(self, s):
        # transform 1e+004 into 1e4, for example
        if self._useLocale:
            decimal_point = locale.localeconv()['decimal_point']
            positive_sign = locale.localeconv()['positive_sign']
        else:
            decimal_point = '.'
            positive_sign = '+'
        tup = s.split('e')
        try:
            significand = tup[0].rstrip('0').rstrip(decimal_point)
            sign = tup[1][0].replace(positive_sign, '')
            exponent = tup[1][1:].lstrip('0')
            if self._useMathText or self._usetex:
                if significand == '1' and exponent != '':
                    # reformat 1x10^y as 10^y
                    significand = ''
                if exponent:
                    exponent = '10^{%s%s}' % (sign, exponent)
                if significand and exponent:
                    return r'%s{\times}%s' % (significand, exponent)
                else:
                    return r'%s%s' % (significand, exponent)
            else:
                s = ('%se%s%s' % (significand, sign, exponent)).rstrip('e')
                return s
        except IndexError:
            return s 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:30,代碼來源:ticker.py


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