python - How to skip a section in config file using configparser -


i have written code parameters taken config file. first parameter in config setting debug level.

    config = configparser.rawconfigparser()     config.read('config.cfg')     log_level = config.get('logger','log_level' ) 

there other sections in config gives server ip , password scan each sections.

main code:

for section in config.sections():     components = dict() #start empty dictionary each section     env.user = config.get(section, 'server.user_name')     env.password = config.get(section, 'server.password')     host = config.get(section, 'server.ip') 

from config

[logger] #possible values logging info, debug , error log_level = debug  [server1] server.user_name = root server.password = password server.ip = 172.19.41.21 [server2] server.user_name = root server.password = password server.ip = 172.19.41.21 

now code says check each section retrieve username , password. since first section doesn't contain these values, it's failing. how can check each section username , password , if not there go next section. tried checking none , go next section. code ugly , it's failing. this:

if env.user=='':         next 

can me proceed further?

add code beginning of for loop:

if not config.has_option(section, 'server.user_name'):     continue 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -