本文整理汇总了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
示例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)
示例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)
示例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)
示例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
#
#-------------------------------------------------------------------------
示例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)
示例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)
示例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')
示例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
示例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')
示例11: setUp
# 需要导入模块: import locale [as 别名]
# 或者: from locale import localeconv [as 别名]
def setUp(self):
self.sep = locale.localeconv()['thousands_sep']
示例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')
示例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):
示例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