본문 바로가기
Computer/python

[ipynb] 쥬피터 노트북에서 %와 !의 차이

by injeolmialmond 2022. 9. 15.

https://stackoverflow.com/questions/45784499/what-is-the-difference-between-and-in-jupyter-notebooks

 

What is the difference between ! and % in Jupyter notebooks?

Both ! and % allow you to run shell commands from a Jupyter notebook. % is provided by the IPython kernel and allows you to run "magic commands", many of which include well-known shell

stackoverflow.com

! 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 immediately terminates.
%cd foo changes the current directory of the notebook process, which is a lasting effect.
  • !는 파이썬 인터프리터에 외치는 것처럼 한 번 외쳐지고 끝나는 것
  • %는 명령어의 영향이 지속됨

댓글