之间有什么区别!和Jupyter笔记本中的%? [英] What is the difference between ! and % in Jupyter notebooks?

查看:56
本文介绍了之间有什么区别!和Jupyter笔记本中的%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

都允许您从Jupyter笔记本运行Shell命令.

Both ! and % allow you to run shell commands from a Jupyter notebook.

  • 提供.IPython内核,并允许您运行魔术命令",其中许多命令都包含众所周知的shell命令.

  • % is provided by the IPython kernel and allows you to run "magic commands", many of which include well-known shell commands.

允许Shell命令在单元中运行.

!, provided by Jupyter, allows shell commands to be run within cells.

我一直找不到很多比较两者,以及简单的shell命令,例如 cd 等.我看到的主要区别是是交互式的,实际上会更改您在shell 在笔记本上.

I haven't been able to find much comparing the two, and for simple shell commands like cd, etc. The main difference I see is that % is interactive and will actually change your location in the shell while in the notebook.

考虑在Jupyter笔记本中用于shell命令的符号时,是否还有其他对比点或规则?

Are there other points or rules of contrast when thinking about which symbol to use for shell commands in a Jupyter notebook?

推荐答案

调用shell(在新进程中),而影响相关的进程使用笔记本(或笔记本本身;许多命令没有对应的shell).

! calls out to a shell (in a new process), while % affects the process associated with the notebook (or the notebook itself; many % commands have no shell counterpart).

!cd foo 本身没有持久作用,因为具有更改目录的进程会立即终止.

!cd foo, by itself, has no lasting effect, since the process with the changed directory immediately terminates.

%cd foo 更改笔记本进程的当前目录,这是持久的作用.

%cd foo changes the current directory of the notebook process, which is a lasting effect.

这篇关于之间有什么区别!和Jupyter笔记本中的%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆