Automation Framework Design Mode --PO self - parametric configuration --ini profiles - simple to read configuration file

Ini file contents inside;

[email_qq]
qq=123456
mm=1sstt
;
[mima]
#r=123
r=12345
t=www.baidu.com

 

 

 

 

 

import configparser
#  C:\\Users\\del\\PycharmProjects\\untitled1\\cs\xs.ini

parse = configparser.ConfigParser()

#parse.read('xs.ini')
parse.read('C:\\Users\\del\\PycharmProjects\\untitled1\\cs\\xs.ini')
sections = parse.sections()


print(sections)

print(parse['mima']['r'])
print(parse['mima']['t'])

 

 

Results of the:

['email_qq', 'mima']
12345
www.baidu.com

 

 

 

 

 

 

 

=======================================================================

ini file contents:

[email_qq]
qq=123456
mm=1sstt
;
[mima]
#r=123
r=12345
t=www.baidu.com

 

Import ConfigParser
 #   C: \\ \\ PycharmProjects the Users del \\ \\ \\ Untitled1 CS \ xs.ini 

the parse = configparser.ConfigParser () 

# parse.read ( 'xs.ini') 
parse.read ( ' C: \ \ PycharmProjects the Users \\ \\ Untitled1 del \\ \\ \\ xs.ini CS ' ) 


Print (parse.sections ())             # Sections () to get all of the section, returns a list form 

Print ( ' ----- ----------------------------- ' ) 

Print (the parse [ ' MIMA ' ] [ ' R & lt ' ])
 Print (the parse [ ' mima' ] [ ' T ' ]) 

Print ( ' ---------------------------------- ' ) 

Print (the parse .items ( ' mima ' ))    # items get all keys to a section of the 

Print ( ' ---------------------------- ---------- ' ) 

Print (parse.options ( ' mima ' ))         # Options (Section) get all option under a Section 



Print ( ' ----------- --------------------------- ' )
 #GET (section, option) to give a value option section, return the string / int type results 


Print (parse.getint ( ' MIMA ' , ' R & lt ' ))
 Print (parse.get ( ' MIMA ' , ' T ' ))

 

 

 

Results of the:

['email_qq', 'mima']
----------------------------------
12345
www.baidu.com
----------------------------------
[('r', '12345'), ('t', 'www.baidu.com')]
--------------------------------------
['r', 't']
--------------------------------------
12345
www.baidu.com

 

Guess you like

Origin www.cnblogs.com/xiaobaibailongma/p/12623893.html