本文整理匯總了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)
示例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
示例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)
示例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
示例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({}))
示例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)
示例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
示例8: __float__
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import isMappingType [as 別名]
def __float__(self):
return 1.0
# obj, isNumberType, isMappingType, isSequenceType
示例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)
示例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({}))