TopHome
<2024-01-23 Tue>pythontech

IPython learnings

Some of this material is from: https://www.youtube.com/watch?v=S9rgGJYAQ8o

1. Clipboard integration

2. The Output gotcha

See if this makes any sense to you…

In [1]: a = [1,3,2]

In [2]: a
Out[2]: [1, 3, 2]

In [3]: _2
Out[3]: [1, 3, 2]

In [4]: a.sort()

In [5]: a
Out[5]: [1, 2, 3]

In [6]: _5
Out[6]: [1, 2, 3]

In [7]: _2
Out[7]: [1, 2, 3]

3. The %rehashx line magic

Loads in local binaries from the filesystem to be directly callable from inside IPython.

4. Events for registring callbacks

5. %prun profiler

See also lineprofiler. %lprun Also, memoryprofiler. %mprun

6. Simple Emacs Integration

If you are editing python code in emacs, the simplest integration is the following:

(setq python-shell-interpreter "ipython"
    python-shell-interpreter-args "-i --simple-prompt")

will replace the python-mode interaction with IPython.

This approach has some downsides though, IPython is running from comint, so you may not get the same terminal level experience. For example, the command numbers will move up faster than you think since some background commands are being run against IPython.