By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 935 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

whos -- a function listing objects

P: n/a
I have been a long time Matlab user. I Python, I miss Matlab's whos
command.

So I have written a little utility whos.py, which can be downloaded
here:
http://beluga.eos.ubc.ca/~tang/softwares/python/

Here is the doc string:

# Before using whos, do:
execfile('whos.py')

#=== EXAMPLES ===
# to see a list of all objects in the global scope
whos()

# to see a list of functions
whos('f')

# to see a list of variables (also their values)
whos('v')

# to see a list of Numeric array
whos('a')

# to see a list of variables in module os
import os
whos('v', module=os)

# to see a list of variables whose name contains 'path'
whos('v', sstr='path')

# to see a list of variables whose name contains 'path' (case
insensitive)
whos('v', sstr='path', casesen=0)

Argument what can be one of the following:
A -- all
a -- array
f -- function
m -- module
v -- variable

Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
>>>>> be*******@yahoo.com (b) wrote:
b> I have been a long time Matlab user. I Python, I miss Matlab's whos
b> command. b> So I have written a little utility whos.py, which can be downloaded
b> here:
b> http://beluga.eos.ubc.ca/~tang/softwares/python/ b> Here is the doc string: b> # Before using whos, do:
b> execfile('whos.py')

execfile('whos.py')
whos()

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "whos.py", line 142, in whos
iType1 = string.split(str(iType), "'")[1]
NameError: global name 'string' is not defined

Using execfile is a bad way to get the function definition. Import is the
way to go. Just add a line:
import string
to the beginning of whos.py, and the the usage should be:

from whos import whos
whos()

or
import whos
whos.whos()
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: pi**@vanoostrum.org
Jul 19 '05 #2

P: n/a
be*******@yahoo.com wrote:
I have been a long time Matlab user. I Python, I miss Matlab's whos
command.


<plug> you might want to look at ipython. whos, and a bit more come for free:

planck[~]> ipython -pylab
Python 2.3.4 (#1, Feb 2 2005, 12:11:53)
Type "copyright", "credits" or "license" for more information.

IPython 0.6.16_cvs -- An enhanced Interactive Python.
? -> Introduction to IPython's features.
%magic -> Information about IPython's 'magic' % functions.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

Welcome to pylab, a matplotlib-based Python environment.
For more information, type 'help(pylab)'.

In [1]: def foo(): pass
...:

In [2]: a=rand(128,128)

In [3]: x=3.14

In [4]: import code

In [5]: whos
Variable Type Data/Info
--------------------------------
a array 128x128: 16384 elems, type `d`, 131072 bytes (128 kb)
code module <module 'code' from '/usr<...>/lib/python2.3/code.pyc'>
foo function <function foo at 0x41203cdc>
x float 3.14

In [6]: whos array
Variable Type Data/Info
-----------------------------
a array 128x128: 16384 elems, type `d`, 131072 bytes (128 kb)

In [7]: whos function
Variable Type Data/Info
--------------------------------
foo function <function foo at 0x41203cdc>

Cheers,

f

Jul 19 '05 #3

P: n/a
whos.py as a module would not work for global scope, as it hides the
function whos in the module scope.

I have fixed the string bug.

Jul 19 '05 #4

P: n/a
That is nice. I didn't know iPython can do whos. Will try it.

iPython seems to infinitely configurable. Hope it will not suck too
much of my time into it.

Jul 19 '05 #5

P: n/a
be*******@yahoo.com wrote:
That is nice. I didn't know iPython can do whos. Will try it.

iPython seems to infinitely configurable. Hope it will not suck too
much of my time into it.


It is. It probably will. It did to me :)

At least, I hope it will have been time well spent.

Best,

f

ps - you mention using matlab. Note that ipython integrates with matplotlib in
its -pylab mode, to provide interactive plotting without blocking for almost
all GUI backends (Tk, GTK, WX and Qt are supported, FLTK is not, though it
might work).

Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.