Getting a dictionnary from a module's variables

ast nomail at com.invalid
Fri Jul 28 08:45:41 EDT 2017


Hello

I have a file conf.py which only contains some
variables definition like that:

a = 7
b = 9
c = 3

In my main program I would like to get a dictionnary
dico = {'a' :7,'b':9, 'c':3}

I tried:

import conf

dico = vars(conf)
but there is among a huge amount of stuff to remove

dir(config) provides a list, some processing is needed to
remove some __identifiers__ and get a dict

Is there a simple way to do that, without processing ?






More information about the Python-list mailing list