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


Python operator.isMappingType方法代码示例

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


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

示例1: test_operator

# 需要导入模块: import operator [as 别名]
# 或者: from operator import isMappingType [as 别名]
def test_operator(self):
        import operator
        self.assertIs(operator.truth(0), False)
        self.assertIs(operator.truth(1), True)
        with test_support.check_py3k_warnings():
            self.assertIs(operator.isCallable(0), False)
            self.assertIs(operator.isCallable(len), True)
        self.assertIs(operator.isNumberType(None), False)
        self.assertIs(operator.isNumberType(0), True)
        self.assertIs(operator.not_(1), False)
        self.assertIs(operator.not_(0), True)
        self.assertIs(operator.isSequenceType(0), False)
        self.assertIs(operator.isSequenceType([]), True)
        self.assertIs(operator.contains([], 1), False)
        self.assertIs(operator.contains([1], 1), True)
        self.assertIs(operator.isMappingType(1), False)
        self.assertIs(operator.isMappingType({}), True)
        self.assertIs(operator.lt(0, 0), False)
        self.assertIs(operator.lt(0, 1), True)
        self.assertIs(operator.is_(True, True), True)
        self.assertIs(operator.is_(True, False), False)
        self.assertIs(operator.is_not(True, True), False)
        self.assertIs(operator.is_not(True, False), True) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_bool.py

示例2: format_string

# 需要导入模块: import operator [as 别名]
# 或者: from operator import isMappingType [as 别名]
def format_string(f, val, grouping=False):
    """Formats a string in the same way that the % formatting would use,
    but takes the current locale into account.
    Grouping is applied if the third parameter is true."""
    percents = list(_percent_re.finditer(f))
    new_f = _percent_re.sub('%s', f)

    if isinstance(val, tuple):
        new_val = list(val)
        i = 0
        for perc in percents:
            starcount = perc.group('modifiers').count('*')
            new_val[i] = format(perc.group(), new_val[i], grouping, False, *new_val[i+1:i+1+starcount])
            del new_val[i+1:i+1+starcount]
            i += (1 + starcount)
        val = tuple(new_val)
    elif operator.isMappingType(val):
        for perc in percents:
            key = perc.group("key")
            val[key] = format(perc.group(), val[key], grouping)
    else:
        # val is a single value
        val = format(percents[0].group(), val, grouping)

    return new_f % val 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:27,代码来源:locale.py

示例3: test_operator

# 需要导入模块: import operator [as 别名]
# 或者: from operator import isMappingType [as 别名]
def test_operator(self):
        import operator
        self.assertIs(operator.truth(0), False)
        self.assertIs(operator.truth(1), True)
        self.assertIs(operator.isCallable(0), False)
        self.assertIs(operator.isCallable(len), True)
        self.assertIs(operator.isNumberType(None), False)
        self.assertIs(operator.isNumberType(0), True)
        self.assertIs(operator.not_(1), False)
        self.assertIs(operator.not_(0), True)
        self.assertIs(operator.isSequenceType(0), False)
        self.assertIs(operator.isSequenceType([]), True)
        self.assertIs(operator.contains([], 1), False)
        self.assertIs(operator.contains([1], 1), True)
        self.assertIs(operator.isMappingType(1), False)
        self.assertIs(operator.isMappingType({}), True)
        self.assertIs(operator.lt(0, 0), False)
        self.assertIs(operator.lt(0, 1), True)
        self.assertIs(operator.is_(True, True), True)
        self.assertIs(operator.is_(True, False), False)
        self.assertIs(operator.is_not(True, True), False)
        self.assertIs(operator.is_not(True, False), True) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:24,代码来源:test_bool.py

示例4: format_string

# 需要导入模块: import operator [as 别名]
# 或者: from operator import isMappingType [as 别名]
def format_string(f, val, grouping=False):
    """Formats a string in the same way that the % formatting would use,
    but takes the current locale into account.
    Grouping is applied if the third parameter is true."""
    percents = list(_percent_re.finditer(f))
    new_f = _percent_re.sub('%s', f)

    if operator.isMappingType(val):
        new_val = []
        for perc in percents:
            if perc.group()[-1]=='%':
                new_val.append('%')
            else:
                new_val.append(format(perc.group(), val, grouping))
    else:
        if not isinstance(val, tuple):
            val = (val,)
        new_val = []
        i = 0
        for perc in percents:
            if perc.group()[-1]=='%':
                new_val.append('%')
            else:
                starcount = perc.group('modifiers').count('*')
                new_val.append(_format(perc.group(),
                                      val[i],
                                      grouping,
                                      False,
                                      *val[i+1:i+1+starcount]))
                i += (1 + starcount)
    val = tuple(new_val)

    return new_f % val 
开发者ID:glmcdona,项目名称:meddle,代码行数:35,代码来源:locale.py

示例5: test_isMappingType

# 需要导入模块: import operator [as 别名]
# 或者: from operator import isMappingType [as 别名]
def test_isMappingType(self):
        self.assertRaises(TypeError, operator.isMappingType)
        self.assertFalse(operator.isMappingType(1))
        self.assertFalse(operator.isMappingType(operator.isMappingType))
        self.assertTrue(operator.isMappingType(operator.__dict__))
        self.assertTrue(operator.isMappingType({})) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_operator.py

示例6: test_module_dict

# 需要导入模块: import operator [as 别名]
# 或者: from operator import isMappingType [as 别名]
def test_module_dict(self):
        currentModule = sys.modules[__name__]
        self.assertEqual(operator.isMappingType(currentModule.__dict__), True)
        self.assertEqual(type({}), type(currentModule.__dict__))
        self.assertEqual(isinstance(currentModule.__dict__, dict), True) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_imp.py

示例7: _sift_tasks

# 需要导入模块: import operator [as 别名]
# 或者: from operator import isMappingType [as 别名]
def _sift_tasks(mapping):
    tasks, collections = [], []
    for name, value in mapping.iteritems():
        if _is_task(name, value):
            tasks.append(name)
        elif isMappingType(value):
            collections.append(name)
    tasks = sorted(tasks)
    collections = sorted(collections)
    return tasks, collections 
开发者ID:prestodb,项目名称:presto-admin,代码行数:12,代码来源:main.py

示例8: __float__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import isMappingType [as 别名]
def __float__(self):
            return 1.0

    # obj, isNumberType, isMappingType, isSequenceType 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:6,代码来源:test_operator_jy.py

示例9: test_isMappingType

# 需要导入模块: import operator [as 别名]
# 或者: from operator import isMappingType [as 别名]
def test_isMappingType(self):
        for obj, _, isMappingType, _ in self.tests:
            self.assert_istype(operator.isMappingType, obj, isMappingType) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:5,代码来源:test_operator_jy.py

示例10: test_isMappingType

# 需要导入模块: import operator [as 别名]
# 或者: from operator import isMappingType [as 别名]
def test_isMappingType(self):
        self.failUnlessRaises(TypeError, operator.isMappingType)
        self.failIf(operator.isMappingType(1))
        self.failIf(operator.isMappingType(operator.isMappingType))
        self.failUnless(operator.isMappingType(operator.__dict__))
        self.failUnless(operator.isMappingType({})) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:8,代码来源:test_operator.py


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