handle handle - 1 year ago 78
Python Question

Get attributes from module imported with star

A python script needs a per-user configuration to override (redefine) "default" assignments (e.g.

path = "local/path/"
) which could by done by importing a custom module's attributes with
from custom_settings import *
. I would like to output the ones that are being changed by the custom module.

From within
its attributes can be obtained with
, e.g.
", ".join( (a for a in dir() if not a.startswith("__") ) )
How can this be done from the importing script if the imported module attributes are bound to the existing namespace?

Answer Source

This may not be the neatest solution, and it seems painfully redundant, but you could always simply:

from custom_settings import *
import custom_settings
overridden = ", ".join(a for a in dir(custom_settings) if not a.startswith("__"))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download