之间的区别!和Jupyter笔记本中的% [英] Difference between ! and % in Jupyter Notebooks

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

问题描述

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

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

%由IPython内核提供 ,并且允许您运行魔术命令",其中许多包含众所周知的shell命令. Jupyter提供的!允许shell命令在单元中运行.

% is provided by the IPython kernel and allows you to run "magic commands", many of which include well-known shell commands. !, 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 Notebook中的shell命令使用哪个符号时是否还有其他对比点或规则?

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

推荐答案

!调用外壳程序(在新进程中),而%影响与笔记本(或笔记本本身;许多笔记本相关)的进程%命令没有对应的Shell).
!cd foo本身没有持久作用,因为具有已更改目录的过程立即终止. %cd foo更改笔记本进程的当前目录,这是持久的作用.

! 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, by itself, has no lasting effect, since the process with the changed directory immediayely terminates. %cd foo changes the current directory of the notebook process, which is a lasting effect.

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

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