Here is a better way to do it:
import sys
definitions = {'a': 1, 'b': 2, 'c': 123.4}
module = sys.modules[__name__]
for name, value in definitions.iteritems():
setattr(module, name, value)
More Related Contents:
- How do I call setattr() on the current module?
- Can I use __init__.py to define global variables?
- Python: Sharing global variables between modules and classes therein
- Why are global variables evil? [closed]
- Python function global variables?
- __getattr__ on a module
- How to make a cross-module variable?
- Execution of Python code with -m option or not
- Why does this UnboundLocalError occur (closure)? [duplicate]
- How to import a Python class that is in a directory above?
- What happens when a module is imported twice?
- I can’t install python-ldap
- Modules are installed using pip on OSX but not found when importing
- How to access a standard-library module in Python when there is a local module with the same name?
- How to create module-wide variables in Python? [duplicate]
- Python import mechanics
- How to compile a Python package to a dll
- how to test if one python module has been imported?
- Homebrew + Python on mac os x 10.8: Fatal Python error: PyThreadState_Get: no current thread importing mapnik
- Global dictionaries don’t need keyword global to modify them? [duplicate]
- What is __path__ useful for?
- UnboundLocalError trying to use a variable (supposed to be global) that is (re)assigned (even after first use)
- How do I install Python libraries in wheel format?
- Python global variable scoping
- How do implicit relative imports work in Python?
- Error: No module named ‘fcntl’
- How do you organize Python modules? [closed]
- Auto-Loading a module on IPython startup
- Module Not Found – No module named
- What’s the difference between a module and package in Python?