Python - Make module method variables global good practice?
<p>I want to separate the code function of a script into a new module. I want to define some configs to pass as parameters in that module. Then, in the module I define this config as global. Is it a good practice? Is there a better solution?</p>

<p><strong>main script:</strong></p>

<pre><code>import myModule

config = {
    "foo1" : "bar1",
    "foo2" : "bar2",
    "foo3" : "bar3"
}

myModule.execute(config)
</code></pre>

<p><strong>module:</strong></p>

<pre><code>def execute(config):
   global CONFIG
   CONFIG = config
   value1, value2 = handleRequest()
   print(value1)
   print(value2)

def handleRequest()
   value1 = doSomething(CONFIG["foo1"])
   value2 = doSomethingElse(CONFIG["foo2"])
   return value1, value2
</code></pre>

<p>What I normally do when I need such kind of global variables is to make a class and define them there. So for example a Configuration class with values stored in them. </p>

<p>This has the following advantages (not an ending list):</p>

<ul>
<li>The class constants/variables 'belong' to something which is more applicable (Configuration in this case).</li>
<li>The code to calculate can be hidden (i.e. functionality can be incorporated in the same class)</li>
<li>Name clashes are prevented. </li>
<li>If in the future there is a need for making multiple instances of configurations it is less of a problem.</li>
</ul>

python python-2.7