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