1樓:
可以方便地應用.來訪問dict的值。
例如,普通的dictionary,訪問值只能用下面的方式:
In [9]: d = }
In [10]: d['foo']
Out[10]: 3
In [11]: d.fooAttributeErrorTraceback (most recent call last)
in ()
----> 1 d.foo
AttributeError: 'dict' object has no attribute 'foo'
使用.來訪問值時,會報錯沒有對應的attribute.
使用edict 包裝後,就不一樣了:
In [12]: from easydict import EasyDict as edict
In [13]: easy = edict(d)
In [14]: easy.foo
Out[14]: 3
就能用.像訪問attribute那樣訪問dictionary的值。
2樓:ljx
EasyDict可以讓你像訪問屬性一樣訪問dict裡的變數。如:
>>>from
easydict
import
EasyDict
asedict
>>>d=
edict
(})>>>d.
foo3
>>>d.
bar.x1
>>>d=
edict
(foo=3
)>>>d.
foo3
python中enumerate object究竟是一種怎樣的存在形式呢?
l Ass We Can type of l is tuplee enumerate l type of e is enumerate objectforv inenumerate e type of enumerate e is enumerate object print v type of v...
Python中ASCII,Unicode,UTF 8,encode,decode這些有什麼關係?
NoOffense ASCII,UTF 8是常用的字元編碼型別,Unicode是字符集,它們跟具體某一門語言 比如Python 無關,是計算機通行的標準。字元編碼型別規定了位元組 bytes 和字元 character 是如何對應的。例如ASCII中,10進製65代字元 A UTF 8中,16進製制...
Python中實現 a and b or c in xx 這種邏輯最簡潔的方式是怎樣的?
意群 不用lambda的話,最簡單的是用all。In 1 a,b,c 1,10,5In 2 xs list range 1 6 In 6 all i inxs foriin a,b orcinxs Out 6 True ohmyfish 使用 Perl 6 中的class Junction 是很簡潔...