本文整理汇总了Python中cyordereddict.OrderedDict.copy方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.copy方法的具体用法?Python OrderedDict.copy怎么用?Python OrderedDict.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cyordereddict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.copy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_copying
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import copy [as 别名]
def test_copying(self):
# Check that ordered dicts are copyable, deepcopyable, picklable,
# and have a repr/eval round-trip
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
od = OrderedDict(pairs)
update_test = OrderedDict()
update_test.update(od)
for label, dup in [
('od.copy()', od.copy()),
('copy.copy(od)', copy.copy(od)),
('copy.deepcopy(od)', copy.deepcopy(od)),
('pickle.loads(pickle.dumps(od, 0))',
pickle.loads(pickle.dumps(od, 0))),
('pickle.loads(pickle.dumps(od, 1))',
pickle.loads(pickle.dumps(od, 1))),
('pickle.loads(pickle.dumps(od, 2))',
pickle.loads(pickle.dumps(od, 2))),
('pickle.loads(pickle.dumps(od, 3))',
pickle.loads(pickle.dumps(od, 3))),
('pickle.loads(pickle.dumps(od, -1))',
pickle.loads(pickle.dumps(od, -1))),
('eval(repr(od))', eval(repr(od))),
('update_test', update_test),
('OrderedDict(od)', OrderedDict(od)),
]:
with self.subTest(label=label):
msg = "\ncopy: %s\nod: %s" % (dup, od)
self.assertIsNot(dup, od, msg)
self.assertEqual(dup, od)
示例2: test_copying
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import copy [as 别名]
def test_copying(self):
# Check that ordered dicts are copyable, deepcopyable, picklable,
# and have a repr/eval round-trip
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
od = OrderedDict(pairs)
def check(dup):
msg = "\ncopy: %s\nod: %s" % (dup, od)
self.assertIsNot(dup, od, msg)
self.assertEqual(dup, od)
check(od.copy())
check(copy.copy(od))
check(copy.deepcopy(od))
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(proto=proto):
check(pickle.loads(pickle.dumps(od, proto)))
check(eval(repr(od)))
update_test = OrderedDict()
update_test.update(od)
check(update_test)
check(OrderedDict(od))
示例3: test_copying
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import copy [as 别名]
def test_copying(self):
# Check that ordered dicts are copyable, deepcopyable, picklable,
# and have a repr/eval round-trip
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
od = OrderedDict(pairs)
update_test = OrderedDict()
update_test.update(od)
for i, dup in enumerate([
od.copy(),
copy.copy(od),
copy.deepcopy(od),
pickle.loads(pickle.dumps(od, 0)),
pickle.loads(pickle.dumps(od, 1)),
pickle.loads(pickle.dumps(od, 2)),
pickle.loads(pickle.dumps(od, -1)),
eval(repr(od)),
update_test,
OrderedDict(od),
]):
self.assertTrue(dup is not od)
self.assertEqual(dup, od)
self.assertEqual(list(dup.items()), list(od.items()))
self.assertEqual(len(dup), len(od))
self.assertEqual(type(dup), type(od))