Viewing all defined variables

Rook picture Rook · Mar 11, 2009 · Viewed 424.4k times · Source

I'm currently working on a computation in python shell. What I want to have is Matlab style listout where you can see all the variables that have been defined up to a point (so I know which names I've used, their values and such).

Is there a way, and how can I do that?

Answer

RedBlueThing picture RedBlueThing · Mar 11, 2009

A few things you could use:

  • dir() will give you the list of in scope variables:
  • globals() will give you a dictionary of global variables
  • locals() will give you a dictionary of local variables