Self-summary (III): with an embodiment of the configurable

The first stage:

Excel when reading data, a mode parameter set, the default value is all, read all the use cases; Example value passed with a list, with the corresponding embodiment performed;

 

By: Advanced profile use cases to determine the execution of

 

1. Create a new file, the file name: config end;

2 consists of three parts, sectionTop (Area must be enclosed in square brackets), Option (option, the left side of the equal sign), value (option, the right of the equal sign)

[MODE]

mode=all

 

3. Read the configuration file: introducing configparser module

cf = configparser.ConfigParser () # instantiated

cf.read ( "case.config", encoding = 'utf-8') # Open File

res = cf.get ( 'MODE', 'mode') # acquires data (with this)

res2 = cf [ 'MODE'] [ 'mode'] # obtain data two ways

 

4. Data types of problems:

Reading out contents are strings, if you want to become the original data, use eval ()

eval (): data from the string into the original data type is limited to a string

 

The tool is written as a class

Guess you like

Origin www.cnblogs.com/test123/p/10981120.html