前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【说站】python ChainMap标准库的跟踪使用

【说站】python ChainMap标准库的跟踪使用

作者头像
很酷的站长
发布2022-11-24 16:34:46
2180
发布2022-11-24 16:34:46
举报
文章被收录于专栏:站长的编程笔记

python ChainMap标准库的跟踪使用

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

可以在模块中找到ChainMap作为一部分。这种方法使用字符串模板作为参数,并且允许在PEP292中替换字符串。输入字符串模板包含嵌入标识符,您可以在以后用实际值替换:Templatestring。

代码语言:javascript
复制
>>> 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在名称冲突时有效地管理输入值的优先级。

代码语言:javascript
复制
>>> 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电脑。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • python ChainMap标准库的跟踪使用
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档