code.interact and imports/definitions visibility
As I wrote in a comment above, the solution is:
code.interact(local=dict(globals(), **locals()))
(taken here)
You are confusing locals()
and globals()
. In a function scope, locals()
lists only names defined in the function itself.
Use globals()
instead.
>>> bar = 'baz'>>> def foo():... spam ='eggs'... print locals()...>>> foo(){'spam': 'eggs'}>>> globals(){'__builtins__': <module '__builtin__' (built-in)>, '__name__': '__main__', 'foo': <function foo at 0x108a027d0>, '__doc__': None, '__package__': None}