How to find the source of global(ish) variable?
Question: 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.

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.

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.


Answer: To get the module of the `commands` object, you could try:

    
    
    import inspect
    inspect.getmodule(commands)
    

