新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:pythonChainMap的管理用法
說明:

1、ChainMap的主要用例是提供一種有效的方法來管理多個(gè)范圍或上下文,并處理重復(fù)鍵的訪問優(yōu)先級(jí)。
2、當(dāng)有多個(gè)存儲(chǔ)重復(fù)鍵的字典訪問它們的順序時(shí),這個(gè)功能非常有用。
在ChainMap文檔中找到一個(gè)經(jīng)典的例子,它模擬python如何分析不同命名空間中的變量名稱。
當(dāng)Python搜索名稱時(shí),它會(huì)依次搜索當(dāng)?shù)?、全局和?nèi)置的功能域,直到找到目標(biāo)名稱。Python作用域是將名稱映射到對(duì)象的字典。
為了模擬Python的內(nèi)部搜索鏈,可以使用鏈映射。
實(shí)例
>>> import builtins >>> # Shadow input with a global name >>> input = 42 >>> pylookup = ChainMap(locals(), globals(), vars(builtins)) >>> # Retrieve input from the global namespace >>> pylookup["input"] 42 >>> # Remove input from the global namespace >>> del globals()["input"] >>> # Retrieve input from the builtins namespace >>> pylookup["input"]
以上就是python ChainMap的管理用法,希望對(duì)大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
當(dāng)前標(biāo)題:創(chuàng)新互聯(lián)Python教程:pythonChainMap的管理用法
網(wǎng)址分享:http://m.fisionsoft.com.cn/article/djciedc.html


咨詢
建站咨詢
