# globals.py x = 1 y = 'abc' class cfg: pass cfg.x = 1 cfg.y = 'abc' import m m.x = 1 m.y = 'abc' # Using global names def f(a,b): global x, y x,y = a,b print "x, y: %s, %s" % (x,y) f('xyz', 5) print "x, y: %s, %s" % (x,y) print # Using class global # Global only within current module def g(a,b): cfg.x,cfg.y = a,b print "cfg.x, cfg.y: %s, %s" % (cfg.x,cfg.y) g('xyz', 5) print "cfg.x, cfg.y: %s, %s" % (cfg.x,cfg.y) print # Using module singleton # Shared across all modules importing m def h(a,b): m.x,m.y = a,b print "m.x, m.y: %s, %s" % (m.x,m.y) h('xyz', 5) print "m.x, m.y: %s, %s" % (m.x,m.y)