0

I have discovered the magic command %%python thanks to this answer, where it prevents a crash of the IPython's kernel after a Tkinter window is closed.

According to the documentation:

%%python
%%python script magic
Run cells with python in a subprocess.

Has this magic command any other use?

Aristide
  • 3,606
  • 2
  • 30
  • 50
  • This command runs a script in a subshell - you use it anytime you want to execute a Python script. Is something in the description unclear? – kabanus Dec 16 '18 at 18:12
  • A Python script is already directly executable as a code cell in Jupyter with a Python kernel (no need to add `%%python`). I add the tag `Jupyter` in case this makes my question clearer. – Aristide Dec 16 '18 at 18:25
  • I know, by subshell I meant a different process is spawned to run the child. I should have emphasized you want to execute the script in a different process - (such as protecting the original process from segmentation faults). This would be necessary to make IPython behave like a "regular" shell. Are there any particular use-cases you are interested in? – kabanus Dec 16 '18 at 18:30
  • Thanks. No, in fact I can't imagine a concrete use case, apart from the one I have discovered in the linked answer. I thought initially that this command would prevent the kernel's lock during the execution of a long-running cell, but the behavior seems identical. – Aristide Dec 16 '18 at 18:34
  • I really think it's just to allow IPython to act as a full fledged terminal. That's why it provides the other magic `%script` commands (`%sh`). – kabanus Dec 16 '18 at 18:36
  • The rest of the docs say it's a shortcut for `%%script python`. Which in turn `is like the #! line of script`. – hpaulj Dec 16 '18 at 19:26

0 Answers0