whos -- a function listing objects

Piet van Oostrum piet at cs.uu.nl
Fri Jun 17 06:15:27 EDT 2005


>>>>> benyang22 at 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 <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list