字典类

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字典类相关的知识,希望对你有一定的参考价值。

This bit of code allows you to turn code that looks like this:

x = {'foo':1, 'bar':2 }
x['foo'] = 3

Into this:
x = dictclass( {'foo':1, 'bar':2 } )
x.foo = 3
  1. class dictclass:
  2. """Takes a dictionary and uses it as its __dict__ member, effectively
  3. making the dictionary supply the object's attributes."""
  4.  
  5. def __init__( self, d ):
  6. self.__dict__ = d

以上是关于字典类的主要内容,如果未能解决你的问题,请参考以下文章