MCPcopy Create free account
hub / github.com/ipython/ipython / edit

Method edit

IPython/core/magics/code.py:521–730  ·  view source on GitHub ↗

Bring up an editor and execute the resulting code. Usage: %edit [options] [args] %edit runs IPython's editor hook. The default version of this hook is set to call the editor specified by your $EDITOR environment variable. If this isn't found, it will defau

(self, parameter_s='',last_call=['',''])

Source from the content-addressed store, hash-verified

519 @skip_doctest
520 @line_magic
521 def edit(self, parameter_s='',last_call=['','']):
522 """Bring up an editor and execute the resulting code.
523
524 Usage:
525 %edit [options] [args]
526
527 %edit runs IPython's editor hook. The default version of this hook is
528 set to call the editor specified by your $EDITOR environment variable.
529 If this isn't found, it will default to vi under Linux/Unix and to
530 notepad under Windows. See the end of this docstring for how to change
531 the editor hook.
532
533 You can also set the value of this editor via the
534 ``TerminalInteractiveShell.editor`` option in your configuration file.
535 This is useful if you wish to use a different editor from your typical
536 default with IPython (and for Windows users who typically don't set
537 environment variables).
538
539 This command allows you to conveniently edit multi-line code right in
540 your IPython session.
541
542 If called without arguments, %edit opens up an empty editor with a
543 temporary file and will execute the contents of this file when you
544 close it (don't forget to save it!).
545
546
547 Options:
548
549 -n <number>: open the editor at a specified line number. By default,
550 the IPython editor hook uses the unix syntax 'editor +N filename', but
551 you can configure this by providing your own modified hook if your
552 favorite editor supports line-number specifications with a different
553 syntax.
554
555 -p: this will call the editor with the same data as the previous time
556 it was used, regardless of how long ago (in your current session) it
557 was.
558
559 -r: use 'raw' input. This option only applies to input taken from the
560 user's history. By default, the 'processed&#x27; history is used, so that
561 magics are loaded in their transformed version to valid Python. If
562 this option is given, the raw input as typed as the command line is
563 used instead. When you exit the editor, it will be executed by
564 IPython&#x27;s own processor.
565
566 -x: do not execute the edited code immediately upon exit. This is
567 mainly useful if you are editing programs which need to be called with
568 command line arguments, which you can then do using %run.
569
570
571 Arguments:
572
573 If arguments are given, the following possibilities exist:
574
575 - If the argument is a filename, IPython will load that into the
576 editor. It will execute its contents with execfile() when you exit,
577 loading any code in the file into your interactive namespace.
578

Callers

nothing calls this directly

Calls 10

_find_edit_targetMethod · 0.95
_edit_macroMethod · 0.95
preserve_keysClass · 0.90
parse_optionsMethod · 0.80
readMethod · 0.80
safe_execfileMethod · 0.80
showtracebackMethod · 0.80
addMethod · 0.45
flushMethod · 0.45
run_cellMethod · 0.45

Tested by

no test coverage detected