"Grep" in Python

I use Python as a command line tool. I wanted to be able to do something similar to dir() | grep cmd to find out what packages had been loaded and variables created. I got sick of searching the net and finding nothing, so here's a simple script that does effectively the same thing (with slightly more tedious syntax):
readfile("python/grep.py"); ?>

If you know of a better (i.e. cleverer) way to accomplish this same feat, please let me know!
Two of the solutions above were provided by a visitor, and I think they are a better solution to the problem presented here.
Personally, I haven't ended up using the 'grep' function as much as I expected; instead I tend to get by on using the Python debugger (pdb) and working on a smaller globals()/locals() list and using who/whos at the ipython command line.

If you are interested in using python on the unix command line in place of grep, I recommend the second hit on google