Getting a dictionnary from a module's variables

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Jul 28 19:04:02 EDT 2017


ast wrote:
> 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 ?

Here's an alternative that leverages the import machinery.

     d = {}
     exec("from config import *", d)
     del d['__builtins__']

-- 
Greg



More information about the Python-list mailing list