Show More
@@ -217,11 +217,6 b' class KernelMagics(Magics):' | |||||
217 | used instead. When you exit the editor, it will be executed by |
|
217 | used instead. When you exit the editor, it will be executed by | |
218 | IPython's own processor. |
|
218 | IPython's own processor. | |
219 |
|
219 | |||
220 | -x |
|
|||
221 | Do not execute the edited code immediately upon exit. This is mainly |
|
|||
222 | useful if you are editing programs which need to be called with |
|
|||
223 | command line arguments, which you can then do using %run. |
|
|||
224 |
|
||||
225 | Arguments: |
|
220 | Arguments: | |
226 |
|
221 | |||
227 | If arguments are given, the following possibilites exist: |
|
222 | If arguments are given, the following possibilites exist: | |
@@ -255,58 +250,11 b' class KernelMagics(Magics):' | |||||
255 | editor. It will execute its contents with execfile() when you exit, |
|
250 | editor. It will execute its contents with execfile() when you exit, | |
256 | loading any code in the file into your interactive namespace. |
|
251 | loading any code in the file into your interactive namespace. | |
257 |
|
252 | |||
258 | After executing your code, %edit will return as output the code you |
|
253 | Unlike in the terminal, this is designed to use a GUI editor, and we do | |
259 | typed in the editor (except when it was an existing file). This way |
|
254 | not know when it has closed. So the file you edit will not be | |
260 | you can reload the code in further invocations of %edit as a variable, |
|
255 | automatically executed or printed. | |
261 | via ``_<NUMBER>` or ``Out[<NUMBER>]``, where <NUMBER> is the prompt number of |
|
|||
262 | the output. |
|
|||
263 |
|
256 | |||
264 | Note that %edit is also available through the alias %ed. |
|
257 | Note that %edit is also available through the alias %ed. | |
265 |
|
||||
266 | This is an example of creating a simple function inside the editor and |
|
|||
267 | then modifying it. First, start up the editor:: |
|
|||
268 |
|
||||
269 | In [1]: ed |
|
|||
270 | Editing... done. Executing edited code... |
|
|||
271 | Out[1]: 'def foo():n print "foo() was defined in an editing session"n' |
|
|||
272 |
|
||||
273 | We can then call the function foo():: |
|
|||
274 |
|
||||
275 | In [2]: foo() |
|
|||
276 | foo() was defined in an editing session |
|
|||
277 |
|
||||
278 | Now we edit foo. IPython automatically loads the editor with the |
|
|||
279 | (temporary) file where foo() was previously defined:: |
|
|||
280 |
|
||||
281 | In [3]: ed foo |
|
|||
282 | Editing... done. Executing edited code... |
|
|||
283 |
|
||||
284 | And if we call foo() again we get the modified version:: |
|
|||
285 |
|
||||
286 | In [4]: foo() |
|
|||
287 | foo() has now been changed! |
|
|||
288 |
|
||||
289 | Here is an example of how to edit a code snippet successive |
|
|||
290 | times. First we call the editor:: |
|
|||
291 |
|
||||
292 | In [5]: ed |
|
|||
293 | Editing... done. Executing edited code... |
|
|||
294 | hello |
|
|||
295 | Out[5]: "print 'hello'n" |
|
|||
296 |
|
||||
297 | Now we call it again with the previous output (stored in _):: |
|
|||
298 |
|
||||
299 | In [6]: ed _ |
|
|||
300 | Editing... done. Executing edited code... |
|
|||
301 | hello world |
|
|||
302 | Out[6]: "print 'hello world'n" |
|
|||
303 |
|
||||
304 | Now we call it with the output #8 (stored in ``_8``, also as Out[8]):: |
|
|||
305 |
|
||||
306 | In [7]: ed _8 |
|
|||
307 | Editing... done. Executing edited code... |
|
|||
308 | hello again |
|
|||
309 | Out[7]: "print 'hello again'n" |
|
|||
310 | """ |
|
258 | """ | |
311 |
|
259 | |||
312 | opts,args = self.parse_options(parameter_s,'prn:') |
|
260 | opts,args = self.parse_options(parameter_s,'prn:') |
General Comments 0
You need to be logged in to leave comments.
Login now