How to do module configuration properly

Jan Kosinski jan.kosinski at
Fri Oct 22 13:22:38 CEST 2010

I have created a python module, which contains a bunch of utility functions that use a number of global variables (directory and file names, etc.).

I want to move that global variables to an external configuration file and I want to load all global variables from that configuration file when module is imported.

I am not sure which is the proper way of doing that. At the moment I use the solution as in the following example, is it fine?
import ConfigParser

config = ConfigParser.SafeConfigParser()
config_f = open('my_module.cfg')
global_var = config.get('section', 'global_var')

def some_func():
    print global_var
import my_module


global_var = /tmp/

More information about the Python-list mailing list