[TriZPUG] Tab completion in python shell
Chris Calloway
cbc at unc.edu
Wed Apr 8 16:33:26 CEST 2015
On 4/8/2015 9:12 AM, Luke Campagnola wrote:
> On Wed, Apr 8, 2015 at 9:14 AM, Chris Calloway <cbc at unc.edu
> <mailto:cbc at unc.edu>> wrote:
> ipython is worth it.
>
> Can you expand on that? I haven't used it much but I presume it provides
> a lot more than history and tab completion.
Gladly, a little (no good deed goes unpunished, right?). There are
hundreds of features, which I assume is what makes it intimidating for
most. But you can just start using it in place of the vanilla
interpreter prompt and learn as you go instead of trying to learn it all
at once. Most of it you will never need anyway.
Out of those hundreds of features, I'd say my favorite is ??, which when
placed after an identifier will take you directly to the source code for
the referenced object. I've learned so much about the internals of
standard library objects because of that.
I think the most popular feature is !, the system escape command. Being
able to issue OS commands in the same shell easily is a no-brainer win.
There are, of course, predefined aliases for things like cd, pwd, etc..
It keeps a directory history that makes it easy to navigate as well as
supporting directory bookmarks. Also, anything in ipython that keeps a
history is exportable.
I would probably use system command aliases more if I had a job where I
did things repetitively every day.
I find persistent command history across sessions useful when it's not
annoying. You can turn it off or clear it, of course.
Logging input to save sessions is indispensable in a job like mine where
I spend a lot of time stumbling into broken code written by other people
and I just want to create a Gist to reference in a Github issue that
demonstrates the problem. (Hey, you earn green dots on GitHub for filing
issues, you know, in case you're a streaker.)
Some features like auto-paren and auto-quote I find silly and don't use.
Cell mode (%%) is like having an Ipython Notebook cell in your
interpreter prompt. There is also a magic command to export your session
to an IPython Notebook.
Bash, Perl, and PowerShell cells.
Direct Github Gist pastebin support.
Inspect support. Get call signatures on demand quickly.
Pretty printing by default.
Profiler support.
SEARCHING FOR OBJECTS IN A NAMESPACE BY NAME AND/OR TYPE!
Special note to people working with GUI toolkits: GUI event loop
integrations for wx, qt4/qt, gtk3/gtk, tk, and Cocoa.
Load numpy and matplotlib in pylab mode. (Actually I find pylab mode
annoying as it encourages non-OO Matlab style programming which simply
has to be unlearned in order to use matplotlib fully. But it is a quick
and dirty path to a plot and low hanging fruit for the legions of Matlab
drones.)
Clear a namespace of interactively defined crap.
Print all interactively defined crap in a namespace.
Namespace dump and load. I have used this on occasion.
If the bazillion things built into ipython aren't enough, there are
bazillions of interactively loadable ipython extensions people have
written. It makes more sense to find or write an ipython extension than
it does to use an ipython alternative like bpython, because ipython is
supported by the NumFocus Foundation and it going to be maintained for
virtual forever.
There are lots of commands and extensions specifically just for IPython
Notebooks, like making matplotlib plot inline into your notebooks or
turning notebooks into reveal.js presentation. Extension culture is hard
to keep up with as people are always coming up with more new cool things
than there is time to investigate.
To get started, just fire up ipython. It immediately prints out a few
commands to get help as soon as it starts. ? gives some very brief
starter pointers. %quickref lists out a lot of commands in brief. %magic
prints out a ton of information.
The most annoying thing about ipython is, "Do you really want to exit
([y]/n)?" Of course, you can turn that off with --no-confirm-exit on the
command line or in your .ipython file. But even having to look that up
was annoying. Unnecessary configuration is alway annoying. Things should
just work right out of the box.
--
Sincerely,
Chris Calloway, Applications Analyst
UNC Renaissance Computing Institute
100 Europa Drive, Suite 540, Chapel Hill, NC 27517
(919) 599-3530
More information about the TriZPUG
mailing list