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


Python OrderedDict.copy方法代码示例

本文整理汇总了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)
开发者ID:aaronjoel,项目名称:cyordereddict,代码行数:31,代码来源:test_ordereddict.py

示例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))
开发者ID:ethanhelfman,项目名称:InstaGet,代码行数:22,代码来源:test_ordereddict.py

示例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))
开发者ID:chebee7i,项目名称:cyordereddict,代码行数:26,代码来源:test_ordereddict.py


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