Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Python 101: Introspection (pythonlibrary.org)
31 points by jnoller on Oct 15, 2010 | hide | past | favorite | 9 comments


Python's easy to use introspection helped me break away from my Visual Studio Intellisense crutch. I remember the days when I didn't know how people code program in a plain text editor (or even vim), because I was so dependent on Intellisense to help me figure out what properties or methods an object or class library had available.

Fast forward a few years and I can hardly stand to use Visual Studio, it's just so slow and clunky! Who needs Intellisense? Just open up the python interpreter and if you're not sure about something you can dir() it :-) But I find myself reading a lot more of the source code and documentation for third party libraries that I'm using. I'm a far different programmer now than I used to be, and I thank Python for helping me progress so quickly.


Also "bpython" is useful for exploratory programming in python and is an able replacement for the standard python shell http://bpython-interpreter.org/ The screenshots speak for themselves: http://bpython-interpreter.org/screenshots/ Some of the features I love are:

* Readline-like autocomplete with suggestions displayed as you type.

* In-line syntax highlighting.

* Displays expected parameter list for any Python function.

* "Rewind" function to pop the last line of code from memory and re-evaluate. etc


I love bpython. It's "just enough" for me, versus ipython, which feels like an 800lbs gorilla.


Also useful: Try running pydoc -p 8000 and then navigating to http://localhost:8000/


Also check out the "see" module. A human readable version of dir():

http://github.com/inky/see


That looks awesome, I can quit doing this:

print '\n'.join(dir(my_object))


I don't use python much anymore, but I am often surprised when talking to python programmers, that if I mention ipython and introspection (e.g. dir() ) they look at me funny. They are missing half the niceness!


Tab completion in the shell makes things even better. I would say simply "check out IPython" but let's say you want to stick with IDLE, you can still get things nice like this:

1. Put this in your user shell RC:

  export PYTHONSTARTUP="~/pycode/pythonrc.py"
2. Put this in pythonrc.py

  import readline, rlcompleter
  readline.parse_and_bind("tab: complete")


Is there a statically typed version of Python? Not a 'language inspired by Python', but a true interpreter derivative that does type enforcement and inferencing?

I ask this because the type() function is awesome.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: