473,414 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

whos -- a function listing objects

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
5 10476
>>>>> 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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
4
by: jbesr1230 | last post by:
Hello, How would I print out a listing of the queries that are in a database? I would like to have a spreadsheet style listing with the columns of: Query Name, Description, Modified Date, Created...
4
by: orekinbck | last post by:
Hi There I am learning about reflection so apologies if this post is vague ... I am doing some unit testing and have written a function that accepts two objects and tests to see if their...
1
by: Ben | last post by:
Hi There I am learning about reflection so apologies if this post is vague ... I am doing some unit testing and have written a function that accepts two objects and tests to see if their...
0
by: dhnriverside | last post by:
Hi all I want to create a webpage that updates say, every 5 minutes (easy), that shows me whos logged on to my network. Any ideas? I've seen this done on an antivirus program, where it pops...
3
by: Zongjun Qi | last post by:
Hey, In the book <Effective C++>, the author provides an example to prove why we need "pass by reference". I redoed the example, and found something interesting. The codes are:...
4
by: Larry | last post by:
On the following page: http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0407zhang/index.html IBM discusses a surrogate key generation function, along with a listing in Java...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.