This talk is an introduction to ipython, which is a much nicer command shell than the default python shell. Presentation slides are here: https://docs.google.com/presentation/d/1rI9iQT9OJHKL7wsaFqNkdGRwI32q3W3F0ojg6Df0Dcg/edit?usp=sharing.
You have a few options:
-
The no install way: Click on
. Once the interface finishes loading, click on New -> Terminal. Once the terminal comes up, type
ipython. -
The slightly harder way: install anaconda python, a python distribution that comes with ipython included. https://docs.anaconda.com/anaconda/install/. Once anaconda is installed and in your path, type
ipython. -
The hard core way: install ipython in your current python distribution. Generally, this will be
pip install ipython. Once installed, typeipython.
-
Make sure you have a prompt that looks something like this. Note that your versions may be slightly different, but you should see the a prompt that says
In [1]:rather than>>>.Python 3.9.2 | packaged by conda-forge | (default, Feb 21 2021, 05:02:46) Type 'copyright', 'credits' or 'license' for more information IPython 7.21.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: -
Print "hello world": type
print("hello world") -
Clear the screen: type
clear -
Get the docstring for the
printfunction: typeprint? -
Execute an os shell command to list the current directory: type
!ls -
Be super lazy and don't even bother with the
!for common os commands likels: typels -
Take advantage of automatic indendation:
In [1]: def foo(): ...: print("foo!") ...: print("baz!") ...: -
Exit
ipythonand start it up again. Hit the up arrow until you get thefoofunction definition from the previous session:In [3]: exit $ ipython Python 3.9.2 | packaged by conda-forge | (default, Feb 21 2021, 05:02:46) Type 'copyright', 'credits' or 'license' for more information IPython 7.21.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: def foo(): ...: print("foo!") ...: print("baz!") -
Search through your command history for the last line that started
pr: typeprat a new prompt and hit the up arrow. -
Carelessly copy and paste a code snippet that still has the
ipythonprompt or thepythonprompt and execute. Copy and paste:>>> print("hello world") -
Read https://ipython.readthedocs.io/en/stable/overview.html for more!