3 ms·
Python 101: Introspection
- megamark16 16y agoPython'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.
- clutchski 16y agoAlso check out the "see" module. A human readable version of dir(): http://github.com/inky/see http://github.com/inky/see
- megamark16 16y agoThat looks awesome, I can quit doing this: print '\n'.join(dir(my_object))
- timf 16y agoTab 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")
- callahad 16y agoAlso useful: Try running pydoc -p 8000 and then navigating to http://localhost:8000/ http://localhost:8000/
- T_S_ 16y agoI 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!
- r11t 16y agoAlso "bpython" is useful for exploratory programming in python and is an able replacement for the standard python shell http://bpython-interpreter.org/ http://bpython-interpreter.org/ The screenshots speak for themselves: http://bpython-interpreter.org/screenshots/ 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
- jnoller 16y agoI love bpython. It's "just enough" for me, versus ipython, which feels like an 800lbs gorilla.
- lhnn 16y agoIs 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.