##// END OF EJS Templates
Mention that suppressing output also bypasses output cache.
Thomas Kluyver -
Show More
@@ -1,100 +1,101 b''
1 1 .. _tips:
2 2
3 3 =====================
4 4 IPython Tips & Tricks
5 5 =====================
6 6
7 7 The `IPython cookbook <http://wiki.ipython.org/Cookbook>`_ details more things
8 8 you can do with IPython.
9 9
10 10 .. This is not in the current version:
11 11
12 12
13 13 Embed IPython in your programs
14 14 ------------------------------
15 15
16 16 A few lines of code are enough to load a complete IPython inside your own
17 17 programs, giving you the ability to work with your data interactively after
18 18 automatic processing has been completed. See :ref:`the embedding section <embedding>`.
19 19
20 20 Run doctests
21 21 ------------
22 22
23 23 Run your doctests from within IPython for development and debugging. The
24 24 special %doctest_mode command toggles a mode where the prompt, output and
25 25 exceptions display matches as closely as possible that of the default Python
26 26 interpreter. In addition, this mode allows you to directly paste in code that
27 27 contains leading '>>>' prompts, even if they have extra leading whitespace
28 28 (as is common in doctest files). This combined with the ``%history -t`` call
29 29 to see your translated history allows for an easy doctest workflow, where you
30 30 can go from doctest to interactive execution to pasting into valid Python code
31 31 as needed.
32 32
33 33 Use IPython to present interactive demos
34 34 ----------------------------------------
35 35
36 36 Use the :class:`IPython.lib.demo.Demo` class to load any Python script as an interactive
37 37 demo. With a minimal amount of simple markup, you can control the execution of
38 38 the script, stopping as needed. See :ref:`here <interactive_demos>` for more.
39 39
40 40 Suppress output
41 41 ---------------
42 42
43 43 Put a ';' at the end of a line to suppress the printing of output. This is
44 44 useful when doing calculations which generate long output you are not
45 interested in seeing.
45 interested in seeing. It also keeps the object out of the output cache, so if
46 you're working with large temporary objects, they'll be released from memory sooner.
46 47
47 48 Lightweight 'version control'
48 49 -----------------------------
49 50
50 51 When you call ``%edit`` with no arguments, IPython opens an empty editor
51 52 with a temporary file, and it returns the contents of your editing
52 53 session as a string variable. Thanks to IPython's output caching
53 54 mechanism, this is automatically stored::
54 55
55 56 In [1]: %edit
56 57
57 58 IPython will make a temporary file named: /tmp/ipython_edit_yR-HCN.py
58 59
59 60 Editing... done. Executing edited code...
60 61
61 62 hello - this is a temporary file
62 63
63 64 Out[1]: "print 'hello - this is a temporary file'\n"
64 65
65 66 Now, if you call ``%edit -p``, IPython tries to open an editor with the
66 67 same data as the last time you used %edit. So if you haven't used %edit
67 68 in the meantime, this same contents will reopen; however, it will be
68 69 done in a new file. This means that if you make changes and you later
69 70 want to find an old version, you can always retrieve it by using its
70 71 output number, via '%edit _NN', where NN is the number of the output
71 72 prompt.
72 73
73 74 Continuing with the example above, this should illustrate this idea::
74 75
75 76 In [2]: edit -p
76 77
77 78 IPython will make a temporary file named: /tmp/ipython_edit_nA09Qk.py
78 79
79 80 Editing... done. Executing edited code...
80 81
81 82 hello - now I made some changes
82 83
83 84 Out[2]: "print 'hello - now I made some changes'\n"
84 85
85 86 In [3]: edit _1
86 87
87 88 IPython will make a temporary file named: /tmp/ipython_edit_gy6-zD.py
88 89
89 90 Editing... done. Executing edited code...
90 91
91 92 hello - this is a temporary file
92 93
93 94 IPython version control at work :)
94 95
95 96 Out[3]: "print 'hello - this is a temporary file'\nprint 'IPython version control at work :)'\n"
96 97
97 98
98 99 This section was written after a contribution by Alexander Belchenko on
99 100 the IPython user list.
100 101
General Comments 0
You need to be logged in to leave comments. Login now