Book contents
- Frontmatter
- Contents
- Preface to the Second Edition
- Preface to the First Edition
- 1 Introduction
- 2 Getting Started with IPython
- 3 A Short Python Tutorial
- 4 NumPy
- 5 Two-Dimensional Graphics
- 6 Multi-Dimensional Graphics
- 7 SymPy: A Computer Algebra System
- 8 Ordinary Differential Equations
- 9 Partial Differential Equations: A Pseudospectral Approach
- 10 Case Study: Multigrid
- Appendix A Installing a Python Environment
- Appendix B Fortran77 Subroutines for Pseudospectral Methods
- References
- Hints for Using the Index
- Index
2 - Getting Started with IPython
Published online by Cambridge University Press: 02 August 2017
- Frontmatter
- Contents
- Preface to the Second Edition
- Preface to the First Edition
- 1 Introduction
- 2 Getting Started with IPython
- 3 A Short Python Tutorial
- 4 NumPy
- 5 Two-Dimensional Graphics
- 6 Multi-Dimensional Graphics
- 7 SymPy: A Computer Algebra System
- 8 Ordinary Differential Equations
- 9 Partial Differential Equations: A Pseudospectral Approach
- 10 Case Study: Multigrid
- Appendix A Installing a Python Environment
- Appendix B Fortran77 Subroutines for Pseudospectral Methods
- References
- Hints for Using the Index
- Index
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
- Python for Scientists , pp. 11 - 20Publisher: Cambridge University PressPrint publication year: 2017