Configparser Module
One,configparser module
1, what is configparser module :configparser module operation configuration file, configuration file format similar to Windows INI and Linux CF file, can contain one or more sections (section) , each section can have multiple parameters (key = value), and its configuration file (INI file) consists of a section, a key, and a value.
2,configparser module Introduction.
Configparser is the package that is used to read the configuration file. The format of the configuration file is as follows: the brackets "[]" are included in the section. section below is a configuration content similar to Key-value.
3, how to generate a configparser configuration file.
1. First import Configparser to call configparser Module #import configparser
2. Create a Configparser configuration file object. #config = configparser. Configparser ()
3. Add content to the configuration file. #config["DEFAULT"] = {' Serveraliveinterval ': ' n ', ' Compression ': ' Yes '}; config[' bitbucket.org '] = {' User ': ' H G '}
4. Open or create a profile, and then add something inside the profile object to the configuration file.
With open (' Example.ini ', ' W ') as ConfigFile:
Config.write (ConfigFile)
5. Read the configuration file. #config.read (' config file name ')
6. When parsing a configuration file using the Configparser module, the problem is found:
The capitalization of the parameter names is all converted to lowercase.
Parameter names cannot contain [,]
If more than one section with the same name is included, the last section will prevail
7. Read the configuration file and write the configuration file.
-read (filename) reads INI file contents directly
-sections () gets all the sections and returns as a list
-options (section) gets all the option of the section
-items (section) gets all the key-value pairs of the section
-get (section,option) Gets the value of option in section, returned as a string type
-getint (section,option) Gets the value of option in section and returns the int type
-add_section (section) Add a new section
-set (section, option, value) to set the option in sections
8. Case Test
See: http://blog.csdn.net/gexiaobaohelloworld/article/details/7976944
Second, subprocess module
1.
Python Basic---function Module 4 (configparser module)