Running Python config content in loop -


i have auto generated file has data in format config.py

abc = {'id':894, 'list':4, 'visiblectx':60} pqr = {'id':84, 'list':3, 'visiblectx':01} xyz = {'id':94, 'list':2, 'visiblectx':10} ... .. . 

i want loop through contents of config file like

while true:     graphicalui.setgraphsctx(config.(list_in_configfile)) 

but unable see how done? have tried regex split each new line based on "=" , run it.

but can other smoother way?

import file module, , run dir() on module object obtain variables.

you can filter out special __ variables using comprehension:

import module var_names = [v v in dir(module) if not v.startswith("__")] 

filter other variables have no interest. once have that, can actual values:

config = { name: getattr(module, name) name in var_names }  

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -