Ask HN: Any tips for using Python Interactively?
I'm SSH'ing into a Ubuntu box using Putty.
I need to run Python in interactive mode and am finding it pretty frustrating.
How do I get the last command? (like using the up arrow at the command line, or in IDLE on Windows Alt-P)
Any other tips?
I'm trying to get IPython going right now but am having some difficulties.
Thanks!
6 comments
[ 2120 ms ] story [ 246 ms ] threadYou might find my pythonrc useful: [link redacted] - be sure to run export PYTHONSTARTUP=~/.pythonrc.py.
My script does the following:
1. Enables readline tab completion. 2. Makes tab insert four spaces. 3. Persists command history (~/.pyhistory). You can disable it by running NOHIST= python. 4. Changes the print hook on functions to include their signature, as well as their documentation. 5. Changes the print hook to use pprint for everything else, also taking into account the terminal width. 6. Colorizes exceptions if Pygments is available. 7. Adds a source() function that shows you the source code of a function, class, or module in your pager. Code is syntax highlighted if Pygments is available. This function works on zipped eggs as well.
Also, enabling readline means all your ~/.inputrc bindings will work. So for example you can hit ^R to search back in history for a snippet you wrote.
what other frustrating things are you finding?
Some other frustrations: reload() seems to not work on occasion(haven't figured out the pattern yet)
Tab completion would be nice (I'm going to try the script above)