Show More
@@ -16,46 +16,46 b' Quick overview:' | |||
|
16 | 16 | =============== |
|
17 | 17 | |
|
18 | 18 | |
|
19 |
All the following construct are valid IPython syntax |
|
|
19 | All the following construct are valid IPython syntax: | |
|
20 | 20 | |
|
21 | .. code-block:: | |
|
21 | .. code-block:: ipython | |
|
22 | 22 |
|
|
23 | ? | |
|
23 | In [1]: ? | |
|
24 | 24 |
|
|
25 | .. code-block:: | |
|
25 | .. code-block:: ipython | |
|
26 | 26 |
|
|
27 | ?object | |
|
27 | In [1]: ?object | |
|
28 | 28 | |
|
29 | 29 | |
|
30 | .. code-block:: | |
|
30 | .. code-block:: ipython | |
|
31 | 31 |
|
|
32 | object? | |
|
32 | In [1]: object? | |
|
33 | 33 |
|
|
34 | .. code-block:: | |
|
34 | .. code-block:: ipython | |
|
35 | 35 |
|
|
36 | *pattern*? | |
|
36 | In [1]: *pattern*? | |
|
37 | 37 |
|
|
38 | .. code-block:: | |
|
38 | .. code-block:: ipython | |
|
39 | 39 |
|
|
40 | %shell like --syntax | |
|
40 | In [1]: %shell like --syntax | |
|
41 | 41 | |
|
42 | .. code-block:: | |
|
42 | .. code-block:: ipython | |
|
43 | 43 |
|
|
44 | !ls | |
|
44 | In [1]: !ls | |
|
45 | 45 | |
|
46 | .. code-block:: | |
|
46 | .. code-block:: ipython | |
|
47 | 47 |
|
|
48 | my_files =! ls ~/ | |
|
49 | for i,file in enumerate(my_file): | |
|
50 | raw = !echo $file | |
|
51 | !echo {files[0].upper()} $raw | |
|
48 | In [1]: my_files =! ls ~/ | |
|
49 | In [1]: for i,file in enumerate(my_file): | |
|
50 | ...: raw = !echo $file | |
|
51 | ...: !echo {files[0].upper()} $raw | |
|
52 | 52 | |
|
53 | 53 | |
|
54 | .. code-block:: | |
|
54 | .. code-block:: ipython | |
|
55 | 55 |
|
|
56 | %%perl magic --function | |
|
57 | @months = ("July", "August", "September"); | |
|
58 | print $months[0]; | |
|
56 | In [1]: %%perl magic --function | |
|
57 | ...: @months = ("July", "August", "September"); | |
|
58 | ...: print $months[0]; | |
|
59 | 59 | |
|
60 | 60 |
|
|
61 | 61 | Each of these construct is compile by IPython into valid python code and will |
@@ -63,18 +63,15 b' do most of the time what you expect it will do. Let see each of these example' | |||
|
63 | 63 | in more detail. |
|
64 | 64 | |
|
65 | 65 | |
|
66 | ||
|
67 | ||
|
68 | ||
|
69 | 66 | Accessing help |
|
70 | 67 | ============== |
|
71 | 68 | |
|
72 | 69 | As IPython is mostly an interactive shell, the question mark is a simple |
|
73 | 70 | shortcut to get help. A question mark alone will bring up the IPython help: |
|
74 | 71 | |
|
75 | .. code-block:: | |
|
72 | .. code-block:: ipython | |
|
76 | 73 |
|
|
77 | In[1]:? | |
|
74 | In [1]: ? | |
|
78 | 75 | |
|
79 | 76 | IPython -- An enhanced Interactive Python |
|
80 | 77 | ========================================= |
@@ -95,7 +92,7 b' shortcut to get help. A question mark alone will bring up the IPython help:' | |||
|
95 | 92 | A single question mark before, or after an object available in current |
|
96 | 93 | namespace will show help relative to this object: |
|
97 | 94 | |
|
98 | .. code-block:: | |
|
95 | .. code-block:: ipython | |
|
99 | 96 |
|
|
100 | 97 | In [6]: object? |
|
101 | 98 | Docstring: The most base type |
@@ -105,7 +102,7 b' namespace will show help relative to this object:' | |||
|
105 | 102 | A double question mark will try to pull out more information about the object, |
|
106 | 103 | and if possible display the python source code of this object. |
|
107 | 104 | |
|
108 | .. code-block:: | |
|
105 | .. code-block:: ipython | |
|
109 | 106 |
|
|
110 | 107 | In[1]: import collections |
|
111 | 108 | In[2]: collection.Counter?? |
@@ -133,7 +130,8 b' If you are looking for an object, the use of wildcards ``*`` in conjunction' | |||
|
133 | 130 | with question mark will allow you to search current namespace for object with |
|
134 | 131 | matching names: |
|
135 | 132 | |
|
136 | .. code-block:: | |
|
133 | .. code-block:: ipython | |
|
134 | ||
|
137 | 135 | In [24]: *int*? |
|
138 | 136 | FloatingPointError |
|
139 | 137 | int |
@@ -149,20 +147,20 b' This is doable through the use of the exclamation mark ``!`` (or bang).' | |||
|
149 | 147 | |
|
150 | 148 | This allow to execute simple command when present in beginning of line: |
|
151 | 149 | |
|
152 | .. code-block:: | |
|
150 | .. code-block:: ipython | |
|
153 | 151 |
|
|
154 | 152 | In[1]: !pwd |
|
155 | 153 | /User/home/ |
|
156 | 154 | |
|
157 | 155 | Change directory: |
|
158 | 156 | |
|
159 | .. code-block:: | |
|
157 | .. code-block:: ipython | |
|
160 | 158 |
|
|
161 | 159 | In[1]: !cd /var/etc |
|
162 | 160 | |
|
163 | 161 | Or edit file: |
|
164 | 162 | |
|
165 | .. code-block:: | |
|
163 | .. code-block:: ipython | |
|
166 | 164 |
|
|
167 | 165 | In[1]: !mvim myfile.txt |
|
168 | 166 | |
@@ -171,7 +169,7 b' The line after the bang can call any program installed in the underlying' | |||
|
171 | 169 | shell, and support variable expansion in the form of ``$variable`` or ``{variable}``. |
|
172 | 170 | The later form of expansion supports arbitrary python expression: |
|
173 | 171 | |
|
174 | .. code-block:: | |
|
172 | .. code-block:: ipython | |
|
175 | 173 |
|
|
176 | 174 | In[1]: file = 'myfile.txt' |
|
177 | 175 | |
@@ -185,14 +183,14 b' in a list-like object (:see:`IPython Slist`) and assign to the left hand side.' | |||
|
185 | 183 | |
|
186 | 184 | This allow you for example to put the list of files of the current working directory in a variable: |
|
187 | 185 | |
|
188 | .. code-block:: | |
|
186 | .. code-block:: ipython | |
|
189 | 187 |
|
|
190 | 188 | In[1]: my_files != ls |
|
191 | 189 | |
|
192 | 190 | |
|
193 | 191 | You can combine the different possibilities in for loops, condition, functions...: |
|
194 | 192 | |
|
195 | .. code-block:: | |
|
193 | .. code-block:: ipython | |
|
196 | 194 |
|
|
197 | 195 | my_files =! ls ~/ |
|
198 | 196 | b = "backup file" |
@@ -211,14 +209,14 b' power. Magic function start with a percent sign (``%``) or double percent (``%%`' | |||
|
211 | 209 | |
|
212 | 210 | A magic call with a sign percent will act only one line: |
|
213 | 211 | |
|
214 | .. code-block:: | |
|
212 | .. code-block:: ipython | |
|
215 | 213 |
|
|
216 | 214 | In[1]: %xmode |
|
217 | 215 | Exception reporting mode: Verbose |
|
218 | 216 | |
|
219 | 217 | And support assignment: |
|
220 | 218 | |
|
221 | .. code-block:: | |
|
219 | .. code-block:: ipython | |
|
222 | 220 |
|
|
223 | 221 | In [1]: results = %timeit -r1 -n1 -o list(range(1000)) |
|
224 | 222 | 1 loops, best of 1: 21.1 µs per loop |
@@ -228,7 +226,7 b' And support assignment:' | |||
|
228 | 226 | |
|
229 | 227 | Magic with two percent sign can spread over multiple lines, but do not support assignment: |
|
230 | 228 | |
|
231 | .. code-block:: | |
|
229 | .. code-block:: ipython | |
|
232 | 230 |
|
|
233 | 231 | In[1]: %%bash |
|
234 | 232 | ... : echo "My shell is:" $SHELL |
@@ -246,6 +244,6 b' Magic with two percent sign can spread over multiple lines, but do not support a' | |||
|
246 | 244 | Combining it all |
|
247 | 245 | ---------------- |
|
248 | 246 | |
|
249 | .. code-block:: | |
|
247 | :: | |
|
250 | 248 | |
|
251 |
find a snippet that combine all that into one thing |
|
|
249 | find a snippet that combine all that into one thing! |
General Comments 0
You need to be logged in to leave comments.
Login now