doctest作用:會(huì)把文檔中注釋的代碼提取并進(jìn)行測試。
成都創(chuàng)新互聯(lián)公司專注于霍州網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供霍州營銷型網(wǎng)站建設(shè),霍州網(wǎng)站制作、霍州網(wǎng)頁設(shè)計(jì)、霍州網(wǎng)站官網(wǎng)定制、小程序定制開發(fā)服務(wù),打造霍州網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供霍州網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
#!/usr/bin/python # -*- coding: utf-8 -*- class Dict(dict): ''' Simple dict but also support access as x.y style. >>> d1 = Dict() >>> d1['x'] = 100 >>> d1.x 100 >>> d1.y = 200 >>> d1['y'] 200 >>> d2 = Dict(a=1, b=2, c='3') >>> d2.c '3' >>> d2['empty'] Traceback (most recent call last): ... KeyError: 'empty' >>> d2.empty Traceback (most recent call last): ... AttributeError: 'Dict' object has no attribute 'empty' ''' def __init__(self, **kw): super(Dict, self).__init__(**kw) def __getattr__(self, key): try: return self[key] except KeyError: raise AttributeError(r"'Dict' object has no attribute '%s'" % key) def __setattr__(self, key, value): self[key] = value if __name__=='__main__': import doctest doctest.testmod()
什么也沒有輸出,證明程序正確。