溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

python中ChainMap標準庫怎么用

發(fā)布時間:2021-09-07 11:32:18 來源:億速云 閱讀:128 作者:小新 欄目:編程語言

這篇文章主要介紹python中ChainMap標準庫怎么用,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

1、在與ChainMap起源密切相關的性能問題中,ConfigParser是其生活中的標準庫模塊。

可以在模塊中找到ChainMap作為一部分。這種方法使用字符串模板作為參數(shù),并且允許在PEP292中替換字符串。輸入字符串模板包含嵌入標識符,您可以在以后用實際值替換:Templatestring。

>>> import string
 
>>> greeting = "Hey $name, welcome to $place!"
>>> template = string.Template(greeting)
 
>>> template.substitute({"name": "Jane", "place": "the World"})
'Hey Jane, welcome to the World!'

2、substitute()替換place提供的關鍵字參數(shù)值,而非輸入字典中的值。

用于ChainMap在名稱沖突時有效地管理輸入值的優(yōu)先級。

>>> import string
 
>>> greeting = "Hey $name, welcome to $place!"
>>> template = string.Template(greeting)
 
>>> template.substitute(
...     {"name": "Jane", "place": "the World"},
...     place="Real Python"
... )
'Hey Jane, welcome to Real Python!'

以上是“python中ChainMap標準庫怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關知識,歡迎關注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI