How to find the source of global(ish) variable?
<p>I inherited some large and unwieldy python code.  In one file its using a list of commands imported from another file.  Looking at it with pdb this commands variable ends up in the global namespace.  However there's another file that doesn't look like its even being used that also has a commands variable in it and for some reason on certain machines that variable is used instead.</p>

<p>My question is, is there a way in pdb or just code to show the source of the commands variable?  I'm hoping for some concrete evidence that shows it's pointing to that file for some reason.</p>

<p>It's a nice demonstration on the dangers of global variables I guess, and I can clean up the code but I'd like to fully understand it first.</p>

<p>To get the module of the <code>commands</code> object, you could try:</p>

<pre><code>import inspect
inspect.getmodule(commands)
</code></pre>

python pdb