One - One Code All

Blog Content

python3中dict.items代替python2的iteritems

Python   2014-04-23 00:28:49

Python 3.x 里面,iteritems() 和 viewitems() 这两个方法都已经废除了,而 items() 得到的结果是和 2.x 里面 viewitems() 一致的。在3.x 里 用 items()替换iteritems() ,可以用于 for 来循环遍历。


for k,v in kw.items():
   setattr(self, k,v)


上一篇:python获得一个对象的所有属性和方法dir()
下一篇:PYTHON利用UNITTEST进行测试用例执行的几种方式

The minute you think of giving up, think of the reason why you held on so long.