forked from ljcooke/see
-
Notifications
You must be signed in to change notification settings - Fork 0
An alternative to Python's dir(). Easy to type; easy to read! For humans only.
License
andreif/see
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
>>> see() An alternative to Python's dir(). Easy to type; easy to read! For humans only. Version: 1.0 Requirements: Python 2.4+ or 3.0 ----------------------------------------------- Sacrilege! Just what do you think you're doing? ----------------------------------------------- Don't get me wrong; dir() is a wonderful little function. Always there to help you out when you chance upon something new and mysterious. I would dare say it's one of my favourites. But wait! There is a problem. Let's face it: dir() isn't exactly easy on the eyes. Say you have a list of everyday items: >>> pencil_case = [ ... 'pencils', 'protractor', 'ruler', ... 'a pair of compasses', 'razor blades', ... 'calculator', 'Garry Gum', ... 'Anti-Garry Gum' ... ] And you want to see what you can do with this list. So you try: >>> dir(pencil_case) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', ' __delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__get item__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', ' __init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__ ', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__str__', 'a ppend', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse' , 'sort'] What a mess. Look at all that code! We didn't want the works -- we were just curious. Help us out here, Computer. This just will not cut it. Enter see(). >>> see(pencil_case) [] in + += * *= < <= == != > >= hash() help() iter() len() repr() reversed() str() .append() .count() .extend() .index() .insert() .pop() .remove() .reverse() .sort() Blimey! There's something different about this one, isn't there? Is this the same pencil_case we had before? I can READ it. There's functions and operators and everything. No underscores or list separators in sight. I am sorry I doubted you, Computer. We can still be friends, yes? ------------------------------------------------- Okay, I'm convinced. How do I install this thing? ------------------------------------------------- If you have root privileges, installing may be as simple as typing sudo easy_install see from a bash shell. If easy_install is not, er, installed on your system, use the accompanying setup.py file instead: sudo python setup.py install For a local install (e.g. for users without root privileges), do: python setup.py install --home="$HOME" Now fire up a Python shell and try out this poetic little number: from see import see With a bit of luck, nothing will explode, and you'll be skimming through object attributes like nobody's business. ------------------------------------------- I don't have to type that every time, do I? ------------------------------------------- Absolutely not! You can make sure see() is available every time you run Python by using a startup file. Simply save the line `from see import see` to a .py file in your home directory (here I'll use the file ~/.pythonrc.py). Then, set the following environment variable (e.g. in ~/.bashrc): export PYTHONSTARTUP="$HOME/.pythonrc.py" Now let's see if it works... $ python Python 2.5.1 (your lottery numbers) Type "help", "copyright", "credits" or "license" for more information. >>> foo = 'bar' >>> see(foo, '.is*') .isalnum() .isalpha() .isdigit() .islower() .isspace() .istitle() .isupper() >>> >>> # success! For iPython users, enabling see() by default requires a little more work. Create a ipy_profile_see.py file in your ~/.ipython directory, and save the following code to it: from IPython import ipapi def main(): ip = ipapi.get() ip.ex('from see import see') main() From here, you have two options: 1. Launch iPython with the command: ipython -profile see 2. Open ~/.ipython/ipy_user_conf.py and add the following line inside the main() function: import ipy_profile_see
About
An alternative to Python's dir(). Easy to type; easy to read! For humans only.
Resources
License
Stars
Watchers
Forks
Languages
- Python 100.0%