In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the example analysis of ChainMap management application settings in python. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
1. ChainMap is particularly useful when managing default configuration values in an application.
ChainMap is one of its main functions, which can set priorities for critical lookup operations.
It seems to be the right tool to solve the problem of managing application configuration.
2. ChainMap allows you to define the appropriate priority for the proxy configuration of the application.
The query keyword searches for cmd_proxy, then local_proxy, and finally system_proxy, which returns the first instance of the current key. In this example, the user does not provide a proxy on the command line, so the application gets the proxy local_proxy from it, which is the next setting provider in the list.
Example
For example, suppose you are developing a command line interface (CLI) application. This application allows the user to specify a proxy service to connect to the Internet. Set the priority to:
Command line option (--proxy,-p)
Use the local profile in the local master table.
System-wide agent structure.
When a user provides an agent on the command line, the application must use the agent. In addition, the application should use the proxy provided in the next configuration object, and so on. It is one of the most common ChainMap. If so, you can do the following:
> from collections import ChainMap > cmd_proxy = {} # The user doesn't provide a proxy > local_proxy = {"proxy": "proxy.local.com"} > system_proxy = {"proxy": "proxy.global.com"} > config = ChainMap (cmd_proxy, local_proxy, system_proxy) > config ["proxy"] 'proxy.local.com' 's sample Analysis of ChainMap Management Application Settings in python "ends here Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.