导语:
本文主要介绍了关于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电脑。
本文为原创文章,版权归知行编程网所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ Python高级架构模式整理01/04
- ♥ python列表的基本用法09/17
- ♥ Python如何清理常驻字符串01/03
- ♥ python 生成器的调用理解12/20
- ♥ Python 基础知识:迭代器以及如何使用它们12/24
- ♥ 告别复制粘贴,Python实现PDF转文本02/23
内容反馈