Skip to main content Accessibility help
×
Hostname: page-component-76fb5796d-qxdb6 Total loading time: 0 Render date: 2024-04-27T17:15:41.339Z Has data issue: false hasContentIssue false

2 - Getting Started with IPython

Published online by Cambridge University Press:  02 August 2017

John M. Stewart
Affiliation:
University of Cambridge
Get access

Summary

This sounds like software produced by Apple®, but it is in fact a Python interpreter on steroids. It has been designed and written by scientists with the aim of offering very fast exploration and construction of code with minimal typing effort, and offering appropriate, even maximal, on-screen help when required. Documentation and much more is available on the website. This chapter is a brief introduction to the essentials of using IPython. A more extended discursive treatment can be found in, e.g., Rossant (2015).

In this chapter we shall concentrate on notebook and terminal modes, and we assume that the reader has set up the environments as described in Sections A.2 and A.3. Before we get to realistic examples, I must ask for the impatient reader's forbearance. Tab completion, Section 2.1, is an unusual but effective method for minimizing key-strokes, and the introspection feature, Section 2.2 shows how to generate relevant inline information quickly, without pausing to consult the manual.

Tab Completion

While using the IPython interpreter, tab completion is always present. This means that, whenever we start typing a Python-related name on a line or in a cell, we can pause and press the tab key, to see a list of names valid in this context, which agree with the characters already typed.

As an example, suppose we need to type import matplotlib. Typing itab reveals 15 possible completions. By inspection, only one of them has second letter m, so that imtab will complete to import. Augmenting this to import mtab shows 30 possibilities, and by inspection we see that we need to complete the command by import matptab to complete the desired line.

That example was somewhat contrived. Here is a more compulsive reason for using tab completion. When developing code, we tend, lazily, to use short names for variables, functions etc. (In early versions of Fortran, we were indeed restricted to six or eight characters, but nowadays the length can be arbitrary.) Short names are not always meaningful ones, and the danger is that if we revisit the code in six months, the intent of the code may no longer be self-evident.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2017

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

Available formats
×