当前位置: 首页>>代码示例>>Python>>正文


Python locale.format方法代码示例

本文整理汇总了Python中locale.format方法的典型用法代码示例。如果您正苦于以下问题:Python locale.format方法的具体用法?Python locale.format怎么用?Python locale.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在locale的用法示例。


在下文中一共展示了locale.format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_mime_icons

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def get_mime_icons(self):
        file_icon = self.style().standardIcon(Qw.QStyle.SP_FileIcon)
        icon_dic = {'folder': self.style().standardIcon(Qw.QStyle.SP_DirIcon),
                    'file': file_icon,
                    'image': file_icon,
                    'audio': file_icon,
                    'video': file_icon,
                    'text': file_icon,
                    'pdf': file_icon,
                    'archive': file_icon}

        # QT RESOURCE FILE WITH MIME ICONS AND DARK GUI THEME ICONS
        # IF NOT AVAILABLE ONLY 2 ICONS REPRESENTING FILE & DIRECTORY ARE USED
        try:
            import resource_file
            for key in icon_dic:
                icon = ':/mimeicons/{}/{}.png'.format(
                    self.setting_params['icon_theme'],
                    key)
                icon_dic[key] = Qg.QIcon(icon)
        except ImportError:
            pass

        return icon_dic 
开发者ID:DoTheEvo,项目名称:ANGRYsearch,代码行数:26,代码来源:angrysearch.py

示例2: upd_dialog_receives_signal

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def upd_dialog_receives_signal(self, message, time):
        if message == 'the_end_of_the_update':
            self.window_close_signal.emit('update_win_ok')
            self.accept()
            return

        label = self[message]
        label_alt = '➔{}'.format(label.text()[1:])
        label.setText(label_alt)

        if self.last_signal:
            prev_label = self[self.last_signal]
            prev_label_alt = '✔{} - {}'.format(prev_label.text()[1:], time)
            prev_label.setText(prev_label_alt)

        self.last_signal = message 
开发者ID:DoTheEvo,项目名称:ANGRYsearch,代码行数:18,代码来源:angrysearch.py

示例3: on_ok_custom_num_window

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def on_ok_custom_num_window(self, *args):
        '''Ok was pressed, create the attribute
        '''
        try:
            val_from = int(self.sp_from.get())
            val_to = int(self.sp_to.get())
            zfill = int(self.sp_zfill.get())
        except ValueError:
            tkinter.messagebox.showerror('Invalid Number', '"From", "To", and "Pad with zeros to width" must all be integers', parent=self.main)
            return
        if val_from > val_to:
            tkinter.messagebox.showerror('Invalid Range', '"From" value must be less than or equal to "To"', parent=self.main)
        elif val_to - val_from > 3000000:
            tkinter.messagebox.showerror('Invalid Range', 'The range must be smaller than 3 million', parent=self.main)
        else:
            if zfill == 0:
                label = 'Numbers: {} - {}'.format(val_from, val_to)
            else:
                label = 'Numbers: {} - {}, zero padding width: {}'.format(val_from, val_to, zfill)
            self.controller.add_attr(label=label,
                                     node_view=self,
                                     attr_class=model.RangeAttr,
                                     start=val_from, end=val_to+1,
                                     zfill=zfill)
            self.cancel_custom_num_window() 
开发者ID:sc0tfree,项目名称:mentalist,代码行数:27,代码来源:adder.py

示例4: on_ok_date_window

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def on_ok_date_window(self):
        '''Ok was pressed, add the date range attribute
        '''
        year_limits = [1, 3000]
        try:
            val_from = int(self.sp_from.get())
            val_to = int(self.sp_to.get())
        except ValueError:
            tkinter.messagebox.showerror('Invalid Value', '"From" year and "To" year must both be integers', parent=self.main)
            return
        if val_from > val_to:
            tkinter.messagebox.showerror('Invalid Value', '"From" year must be less than or equal to "To" year', parent=self.main)
        elif val_to - val_from > 200:
            tkinter.messagebox.showerror('Invalid Value', 'Distance between "From" year and "To" year must be 200 or less', parent=self.main)
        elif val_from < year_limits[0] or val_to > year_limits[1]:
            tkinter.messagebox.showerror('Invalid Range', 'The year must be between {} and {}'.format(*year_limits), parent=self.main)
        else:
            label = 'Date: {} - {}, format: {}, {}'.format(val_from, val_to, self.date_format.get(), ['no leading zero', 'with leading zero'][self.date_zero_padding.get()==1])
            self.controller.add_attr(label=label, node_view=self, attr_class=model.DateRangeAttr, start_year=val_from, end_year=val_to+1, format=self.date_format.get(), zero_padding=self.date_zero_padding.get()==1, controller=self.controller)
            self.cancel_custom_num_window() 
开发者ID:sc0tfree,项目名称:mentalist,代码行数:22,代码来源:adder.py

示例5: buildBody

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def buildBody(self, bodies, boundary):
        body = ''
        for b in bodies:
            body += ('--' + boundary + "\r\n")
            body += ('Content-Disposition: ' + b['type'] + '; name="' + b['name'] + '"')
            if 'filename' in b:
                ext = os.path.splitext(b['filename'])[1][1:]
                body += ('; filename="' + 'pending_media_' + locale.format("%.*f", (
                    0, round(float('%.2f' % time.time()) * 1000)), grouping=False) + '.' + ext + '"')
            if 'headers' in b and isinstance(b['headers'], list):
                for header in b['headers']:
                    body += ("\r\n" + header)
            body += ("\r\n\r\n" + str(b['data']) + "\r\n")
        body += ('--' + boundary + '--')

        return body 
开发者ID:danleyb2,项目名称:Instagram-API,代码行数:18,代码来源:HttpInterface.py

示例6: stringFromNumber

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def stringFromNumber(self, number, decimals=None):
        # Uses the current system locale, irrespective of language choice.
        # Unless `decimals` is specified, the number will be formatted with 5 decimal
        # places if the input is a float, or none if the input is an int.
        if decimals == 0 and not isinstance(number, numbers.Integral):
            number = int(round(number))
        if platform == 'darwin':
            if not decimals and isinstance(number, numbers.Integral):
                return self.int_formatter.stringFromNumber_(number)
            else:
                self.float_formatter.setMinimumFractionDigits_(decimals or 5)
                self.float_formatter.setMaximumFractionDigits_(decimals or 5)
                return self.float_formatter.stringFromNumber_(number)
        else:
            if not decimals and isinstance(number, numbers.Integral):
                return locale.format('%d', number, True)
            else:
                return locale.format('%.*f', (decimals or 5, number), True) 
开发者ID:EDCD,项目名称:EDMarketConnector,代码行数:20,代码来源:l10n.py

示例7: numberFromString

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [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

示例8: param

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def param(name, *args, **kwargs):
    """
    A wrapper for `tf.Variable` which enables parameter sharing in models.
    
    Creates and returns theano shared variables similarly to `tf.Variable`, 
    except if you try to create a param with the same name as a 
    previously-created one, `param(...)` will just return the old one instead of 
    making a new one.

    This constructor also adds a `param` attribute to the shared variables it 
    creates, so that you can easily search a graph for all params.
    """

    if name not in _params:
        kwargs['name'] = name
        param = tf.Variable(*args, **kwargs)
        param.param = True
        _params[name] = param
    result = _params[name]
    i = 0
    while result in _param_aliases:
        # print 'following alias {}: {} to {}'.format(i, result, _param_aliases[result])
        i += 1
        result = _param_aliases[result]
    return result 
开发者ID:igul222,项目名称:improved_wgan_training,代码行数:27,代码来源:__init__.py

示例9: test_float_to_string

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def test_float_to_string(self):
        def test(f, result):
            self.assertEqual(f.__format__('e'), result)
            self.assertEqual('%e' % f, result)

        # test all 2 digit exponents, both with __format__ and with
        #  '%' formatting
        for i in range(-99, 100):
            test(float('1.5e'+str(i)), '1.500000e{0:+03d}'.format(i))

        # test some 3 digit exponents
        self.assertEqual(1.5e100.__format__('e'), '1.500000e+100')
        self.assertEqual('%e' % 1.5e100, '1.500000e+100')

        self.assertEqual(1.5e101.__format__('e'), '1.500000e+101')
        self.assertEqual('%e' % 1.5e101, '1.500000e+101')

        self.assertEqual(1.5e-100.__format__('e'), '1.500000e-100')
        self.assertEqual('%e' % 1.5e-100, '1.500000e-100')

        self.assertEqual(1.5e-101.__format__('e'), '1.500000e-101')
        self.assertEqual('%e' % 1.5e-101, '1.500000e-101')

        self.assertEqual('%g' % 1.0, '1')
        self.assertEqual('%#g' % 1.0, '1.00000') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_types.py

示例10: test_int__format__locale

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def test_int__format__locale(self):
        # test locale support for __format__ code 'n' for integers

        x = 123456789012345678901234567890
        for i in range(0, 30):
            self.assertEqual(locale.format('%d', x, grouping=True), format(x, 'n'))

            # move to the next integer to test
            x = x // 10

        rfmt = ">20n"
        lfmt = "<20n"
        cfmt = "^20n"
        for x in (1234, 12345, 123456, 1234567, 12345678, 123456789, 1234567890, 12345678900):
            self.assertEqual(len(format(0, rfmt)), len(format(x, rfmt)))
            self.assertEqual(len(format(0, lfmt)), len(format(x, lfmt)))
            self.assertEqual(len(format(0, cfmt)), len(format(x, cfmt))) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_types.py

示例11: test_format_spec_errors

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def test_format_spec_errors(self):
        # int, float, and string all share the same format spec
        # mini-language parser.

        # Check that we can't ask for too many digits. This is
        # probably a CPython specific test. It tries to put the width
        # into a C long.
        self.assertRaises(ValueError, format, 0, '1'*10000 + 'd')

        # Similar with the precision.
        self.assertRaises(ValueError, format, 0, '.' + '1'*10000 + 'd')

        # And may as well test both.
        self.assertRaises(ValueError, format, 0, '1'*1000 + '.' + '1'*10000 + 'd')

        # Make sure commas aren't allowed with various type codes
        for code in 'xXobns':
            self.assertRaises(ValueError, format, 0, ',' + code) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_types.py

示例12: print_params_info

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def print_params_info(params):
    """Print information about the parameters in the given param set."""

    params = sorted(params, key=lambda p: p.name)
    values = [p.get_value(borrow=True) for p in params]
    shapes = [p.shape for p in values]
    print "Params for cost:"
    for param, value, shape in zip(params, values, shapes):
        print "\t{0} ({1})".format(
            param.name,
            ",".join([str(x) for x in shape])
        )

    total_param_count = 0
    for shape in shapes:
        param_count = 1
        for dim in shape:
            param_count *= dim
        total_param_count += param_count
    print "Total parameter count: {0}".format(
        locale.format("%d", total_param_count, grouping=True)
    ) 
开发者ID:igul222,项目名称:pixel_rnn,代码行数:24,代码来源:utils.py

示例13: test_edit_recebimento_movimentar_caixa_false_get_post_request

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def test_edit_recebimento_movimentar_caixa_false_get_post_request(self):
        # Buscar entrada com movimento de caixa e data_pagamento
        obj = Entrada.objects.filter(status='0', movimentar_caixa=True).exclude(Q(movimento_caixa__isnull=True) | Q(
            data_pagamento__isnull=True) | Q(data_pagamento=datetime.strptime('06/07/2017', "%d/%m/%Y").date())).order_by('pk').last()
        url = reverse('financeiro:editarrecebimentoview',
                      kwargs={'pk': obj.pk})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        data = response.context['form'].initial
        replace_none_values_in_dictionary(data)
        data['descricao'] = 'Recebimento editado'
        data['valor_total'] = locale.format(
            u'%.2f', Decimal(data['valor_total']), 1)
        data['valor_liquido'] = locale.format(
            u'%.2f', Decimal(data['valor_liquido']), 1)
        data['movimentar_caixa'] = False
        response = self.client.post(url, data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(
            response, 'financeiro/lancamento/lancamento_list.html')

        # Verificar se movimento foi removido do lancamento
        obj.refresh_from_db()
        self.assertIsNone(obj.movimento_caixa) 
开发者ID:thiagopena,项目名称:djangoSIGE,代码行数:26,代码来源:test_views.py

示例14: test_edit_pagamento_movimentar_caixa_false_get_post_request

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def test_edit_pagamento_movimentar_caixa_false_get_post_request(self):
        # Buscar saida com movimento de caixa e data_pagamento
        obj = Saida.objects.filter(status='0', movimentar_caixa=True).exclude(Q(movimento_caixa__isnull=True) | Q(
            data_pagamento__isnull=True) | Q(data_pagamento=datetime.strptime('06/07/2017', "%d/%m/%Y").date())).order_by('pk').last()
        url = reverse('financeiro:editarpagamentoview',
                      kwargs={'pk': obj.pk})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        data = response.context['form'].initial
        replace_none_values_in_dictionary(data)
        data['descricao'] = 'Pagamento editado'
        data['valor_total'] = locale.format(
            u'%.2f', Decimal(data['valor_total']), 1)
        data['valor_liquido'] = locale.format(
            u'%.2f', Decimal(data['valor_liquido']), 1)
        data['movimentar_caixa'] = False
        response = self.client.post(url, data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(
            response, 'financeiro/lancamento/lancamento_list.html')

        # Verificar se movimento foi removido do lancamento
        obj.refresh_from_db()
        self.assertIsNone(obj.movimento_caixa) 
开发者ID:thiagopena,项目名称:djangoSIGE,代码行数:26,代码来源:test_views.py

示例15: get_aliquota_pis

# 需要导入模块: import locale [as 别名]
# 或者: from locale import format [as 别名]
def get_aliquota_pis(self, format=True):
        try:
            pis_padrao = PIS.objects.get(
                grupo_fiscal=self.produto.grupo_fiscal)

            if pis_padrao.valiq_pis:
                if format:
                    return locale.format(u'%.2f', pis_padrao.valiq_pis, 1)
                else:
                    return pis_padrao.valiq_pis
            elif pis_padrao.p_pis:
                if format:
                    return locale.format(u'%.2f', pis_padrao.p_pis, 1)
                else:
                    return pis_padrao.p_pis

        except PIS.DoesNotExist:
            return 
开发者ID:thiagopena,项目名称:djangoSIGE,代码行数:20,代码来源:vendas.py


注:本文中的locale.format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。