カスタム辞書

クラスTest1を(辞書):
     デフ __init__ (自己):
        self.update()
        self.load()

    DEF 更新(自己):
         プリント ' 更新执行' 

    DEF 負荷(自己):
        K = ' キー' 
        V = ' ' 
        のdict 。__setitem__ (自己、K、V)
     DEF  __setitem__ (自己、キー、値):
         印刷 ' __setitem__执行' 
        自己。__dict__ [キー] = リターン辞書。__setitem__(自己、' K1 '' V1 ' 

T = Test1を()
のt [ ' ' ] = ' B ' プリント T。__dict__#{ 'A': 'B'} 印刷 t.get(' キー' )#値
 プリント t.get( 'A')#なし印刷 t.get(' K1 ')#1 V1

 

おすすめ

転載: www.cnblogs.com/yaraning/p/11349676.html
おすすめ