I keep forgetting about this interesting gem of a feature in org-mode code blocks. You can put references to specific lines of code outside the block! http://orgmode.org/manual/Literal-examples.html#Literal-examples
The following code block has some references in it that we can refer to later:
#+BEGIN_SRC emacs-lisp -n -r (save-excursion (sc) (goto-char (point-min))) (jump) #+END_SRC
1: (save-excursion 2: (goto-char (point-min)))
(sc)we remember the current position.
(jump)jumps to point-min.
To make this work with python we have to make a slight change to the reference format in the header.
#+BEGIN_SRC python -n -r -l "#(ref:%s)" for i in range(5): # (for) print i # (body) #+END_SRC
1: for i in range(5): 2: print i
0 1 2 3 4
(for)we initialize the loop, and in line
(body)we run it.
Copyright (C) 2014 by John Kitchin. See the License for information about copying.
Org-mode version = 8.2.5h