Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use ChainMap Standard Library in python

Shulou Source: shulou.com Published: 2022-06-03 17:38:58 10月03日 Update

This article mainly introduces how to use the ChainMap standard library in python. It is very detailed and has a certain reference value. Friends who are interested must finish it!

1. Among the performance problems closely related to the origin of ChainMap, ConfigParser is the standard library module in its life.

You can find ChainMap as part of the module. This approach takes a string template as a parameter and allows strings to be replaced in PEP292. The input string template contains an embedded identifier, which you can later replace with the actual value: 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 wordings'

2. Substitute () replaces the keyword parameter value provided by place instead of the value in the input dictionary.

Used by ChainMap to effectively manage the priority of input values in the event of name conflicts.

> 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' These are all the contents of the article "how to use the ChainMap Standard Library in python". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Standard character string input content parameter module template article value priority key keyword interest name dictionary actual buddy partner performance Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Redmi MariaDB Microsoft Shulou Technology