知行编程网知行编程网  2023-01-14 03:30 知行编程网 隐藏边栏  5 
文章评分 0 次,平均分 0.0
导语: 本文主要介绍了关于python ChainMap标准库的跟踪使用的相关知识,希望可以帮到处于编程学习途中的小伙伴

追踪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!'


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

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写
扫一扫二维码分享