How do I get around uninitialized global variables in another module in Python?
<p>I have a problem where I'm trying to use a function from another module but that function calls a debug function which checks if a global variable has a certain attribute. This global variable is not set (otherwise set using <code>parser.parse_args</code>) when I import the function so the function complains that the attribute doesn't exist. For clarification: </p>

<p>File <code>findfile.py</code>:</p>

<pre><code>_args = {}

def _debug(msg):
    if _TEST and _args.debug:
        print msg

def findfile(filename):
    ...
    _debug("found file")
    ...

if __name__ == "__main__":
    ...
    _args = parser.parse_args()
    ...
</code></pre>

<p>File <code>copyafile.py</code></p>

<pre><code>import findfile

findfile.findfile("file1")
</code></pre>

<p>This gives me</p>

<pre><code>AttributeError: 'dict' object has no attribute 'debug'
</code></pre>

<p>Now I understand that <code>parser.parse_args()</code> returns a namespace (??) and that <code>_args.debug</code> isn't really looking in the <code>dict</code>. But my question is: How can I in this situation properly assign something to <code>_args</code> to set the <code>_args.debug</code> to <code>False</code>?</p>

<p><strong>I can not change <code>findfile.py</code> but I can change <code>copyafile.py</code>.</strong></p>

<p>How are these things usually handled otherwise? What is the pythonic way of enabling debug flags in a script?</p>
