Coder Social home page Coder Social logo

see's Introduction

see()

An alternative to Python's dir(). Easy to type; easy to read! For humans only.

  • Version: 0.3

  • Requirements: Python

    • Works with 2.4+
    • Not tested yet with 3.0, but some changes in this version have been taken into account

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']
pencil_case.append('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__', '__delsli
ce__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__gets
lice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '
__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__r
educe_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__
', '__setslice__', '__str__', 'append', 'count', 'extend', 'index', 'insert', 'p
op', '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)
  ?   []   for   in   +   *   +=   *=   <   <=   ==   !=   >   >=   len()
  .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're lucky enough to be using Linux, OS X, or anything similar, simply type:

sudo python setup.py install

Or, if you don't have root privileges:

python setup.py install --home=~

(If you're using Windows, I can't help you out, I'm afraid. A Windows installer will appear soon!)

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 attributes like nobody's business.

To make things even more fun, you can make sure see is available every time you run Python. How? you might ask. By using a startup file. Simply save the line above (from see import see) to a .py file — let's use the file ~/.pythonrc.py. Then, set the following environment variable (e.g. in .bashrc):

export PYTHONSTARTUP="$HOME/.pythonrc.py"

If you are using iPython, enabling see by default is slightly more involved. Create a file ipy_profile_see.py in your ~/.ipython/ directory and copy the following contents into the file:

from IPython import ipapi

def main():
    ip = ipapi.get()
    ip.ex('from see import see')

main()

And then you can launch iPython with see already imported by giving the command ipython -profile see or you can make it the default choice by adding the line import ipy_profile_see anywhere inside the main() function as given in the file ~/.ipython/ipy_user_conf.py.

Now let's see if it works...

bash$ python
Python 2.5.1 (your lottery numbers)
Type "help", "copyright", "credits" or "license" for more information.
>>> foo = 'bar'
>>> see(foo)
  ?   []   in   +   *   %   <   <=   ==   !=   >   >=   len()   .capitalize()
  .center()   .count()   .decode()   .encode()   .endswith()   .expandtabs()
  .find()   .index()   .isalnum()   .isalpha()   .isdigit()   .islower()
  .isspace()   .istitle()   .isupper()   .join()   .ljust()   .lower()
  .lstrip()   .partition()   .replace()   .rfind()   .rindex()   .rjust()
  .rpartition()   .rsplit()   .rstrip()   .split()   .splitlines()
  .startswith()   .strip()   .swapcase()   .title()   .translate()   .upper()
  .zfill()
>>>
>>> # success!
...

Acknowledgements

Some thanks are in order:

  • akuhn for the reddit linkage
  • CommodoreGuff for pointing out stuff that didn't work in Python 3
  • ghoseb for contributing iPython instructions
  • igowen for fixing the link to the startup file documentation (Python 1.5 — what was I thinking?)

see's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.