本文整理汇总了Python中persistent.mapping.PersistentMapping.iterkeys方法的典型用法代码示例。如果您正苦于以下问题:Python PersistentMapping.iterkeys方法的具体用法?Python PersistentMapping.iterkeys怎么用?Python PersistentMapping.iterkeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类persistent.mapping.PersistentMapping
的用法示例。
在下文中一共展示了PersistentMapping.iterkeys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkBasicOps
# 需要导入模块: from persistent.mapping import PersistentMapping [as 别名]
# 或者: from persistent.mapping.PersistentMapping import iterkeys [as 别名]
def checkBasicOps(self):
from persistent.mapping import PersistentMapping
m = PersistentMapping({'x': 1}, a=2, b=3)
m['name'] = 'bob'
self.assertEqual(m['name'], "bob")
self.assertEqual(m.get('name', 42), "bob")
self.assert_('name' in m)
try:
m['fred']
except KeyError:
pass
else:
self.fail("expected KeyError")
self.assert_('fred' not in m)
self.assertEqual(m.get('fred'), None)
self.assertEqual(m.get('fred', 42), 42)
keys = m.keys()
keys.sort()
self.assertEqual(keys, ['a', 'b', 'name', 'x'])
values = m.values()
values.sort()
self.assertEqual(values, [1, 2, 3, 'bob'])
items = m.items()
items.sort()
self.assertEqual(items,
[('a', 2), ('b', 3), ('name', 'bob'), ('x', 1)])
keys = list(m.iterkeys())
keys.sort()
self.assertEqual(keys, ['a', 'b', 'name', 'x'])
values = list(m.itervalues())
values.sort()
self.assertEqual(values, [1, 2, 3, 'bob'])
items = list(m.iteritems())
items.sort()
self.assertEqual(items,
[('a', 2), ('b', 3), ('name', 'bob'), ('x', 1)])
示例2: checkBasicOps
# 需要导入模块: from persistent.mapping import PersistentMapping [as 别名]
# 或者: from persistent.mapping.PersistentMapping import iterkeys [as 别名]
def checkBasicOps(self):
from persistent.mapping import PersistentMapping
m = PersistentMapping({"x": 1}, a=2, b=3)
m["name"] = "bob"
self.assertEqual(m["name"], "bob")
self.assertEqual(m.get("name", 42), "bob")
self.assert_("name" in m)
try:
m["fred"]
except KeyError:
pass
else:
self.fail("expected KeyError")
self.assert_("fred" not in m)
self.assertEqual(m.get("fred"), None)
self.assertEqual(m.get("fred", 42), 42)
keys = m.keys()
keys.sort()
self.assertEqual(keys, ["a", "b", "name", "x"])
values = m.values()
values.sort()
self.assertEqual(values, [1, 2, 3, "bob"])
items = m.items()
items.sort()
self.assertEqual(items, [("a", 2), ("b", 3), ("name", "bob"), ("x", 1)])
keys = list(m.iterkeys())
keys.sort()
self.assertEqual(keys, ["a", "b", "name", "x"])
values = list(m.itervalues())
values.sort()
self.assertEqual(values, [1, 2, 3, "bob"])
items = list(m.iteritems())
items.sort()
self.assertEqual(items, [("a", 2), ("b", 3), ("name", "bob"), ("x", 1)])