whos and clear (as in matlab) functionality

Thomas Knudsen thk at kms.dk
Thu Mar 20 11:02:57 CET 2003

I'm a python newbie, currently in the process of moving
parts of my work from Matlab to python + Numeric.

When using python interactively, I  often need something
like the Matlab "whos" command.

In Matlab "whos" returns a list of all variables:
>> a = 4;
>> b = [1 2 3; 4 5 6];
>> whos
  Name      Size                   Bytes  Class

  a         1x1                        8  double array
  b         2x3                       48  double array

Grand total is 7 elements using 56 bytes

is there any way of doing something similar in python?
A recent post by Michael Chermside, in the thread
"How to get the 'name' of an int" suggests the following for
the slightly different task of listing names and values:

            for name, value in locals().iteritems():
                print "%s = %s" % (name, value)

any suggestions of how I could change this to name, type?

On a related note, the Matlab commands "clear all; pack"
clears all variables in the current namespace and starts
garbage collection. Is there a corresponding python idiom?

thomas knudsen  -  kms, copenhagen, denmark  -  http://research.kms.dk/~thk

More information about the Python-list mailing list