1、在与ChainMap起源密切相关的性能问题中,ConfigParser是其生活中的标准库模块。
可以在模块中找到ChainMap作为一部分。这种方法使用字符串模板作为参数,并且允许在PEP292中替换字符串。输入字符串模板包含嵌入标识符,您可以在以后用实际值替换:Templatestring。
>>>importstring >>>greeting="Hey$name,welcometo$place!" >>>template=string.Template(greeting) >>>template.substitute({"name":"Jane","place":"theWorld"}) 'HeyJane,welcometotheWorld!'
2、substitute()替换place提供的关键字参数值,而非输入字典中的值。
用于ChainMap在名称冲突时有效地管理输入值的优先级。
>>>importstring >>>greeting="Hey$name,welcometo$place!" >>>template=string.Template(greeting) >>>template.substitute( ...{"name":"Jane","place":"theWorld"}, ...place="RealPython" ...) 'HeyJane,welcometoRealPython!'
以上就是python ChainMap标准库的跟踪使用,希望对大家有所帮助。更多Python学习指路:Python基础教程
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)