创新互联Python教程:python ChainMap标准库的跟踪使用

1、在与ChainMap起源密切相关的性能问题中,ConfigParser是其生活中的标准库模块。

可以在模块中找到ChainMap作为一部分。这种方法使用字符串模板作为参数,并且允许在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提供的关键字参数值,而非输入字典中的值。

用于ChainMap在名称冲突时有效地管理输入值的优先级。

>>> 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标准库的跟踪使用,希望对大家有所帮助。更多Python学习指路:创新互联python教程

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。


网站名称:创新互联Python教程:python ChainMap标准库的跟踪使用
本文路径:http://bzwzjz.com/article/cdsjged.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 成都网站设计 手机网站制作 做网站设计 成都网站建设公司 成都企业网站制作 成都网站设计 成都网站制作公司 网站制作 成都响应式网站建设 企业网站建设 梓潼网站设计 成都网站制作 成都网站设计制作公司 成都网站建设公司 企业网站设计 网站建设 手机网站建设套餐 成都网站设计公司 营销网站建设 重庆企业网站建设 营销型网站建设 自适应网站建设