1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

IPythonの個人的に使うコマンド備忘録

Last updated at Posted at 2022-06-26

概要

IPythonで個人的に使うコマンド類を忘れた時のためにメモしておく。

環境

$ python --version
Python 3.10.0
$ ipython --version
8.4.0

内容

%save 今までのセッションの保存(.pyへ)

IPython
In [25]: %save -r tmp.py

-rはraw inputの意味。
追記する場合は、-aも付ければ良い。

%notebook 今までのセッションの保存(.ipynbへ)

IPython
In [25]: %notebook tmp.ipynb

%edit 複数行の入力・編集

IPython
In [32]: %edit

これでエディタが開くので適当なコードを入力して保存終了する。

IPython
In [32]: %edit
IPython will make a temporary file named: /var/folders/8h/jhj4lrhd1fv7xz3bxhdxxzyh0000gn/T/ipython_edit_d59j_wf5/ipython_edit_xzlshns7.py
Editing... done. Executing edited code...
0
3
6
Out[32]: 'for i in range(3):\n    j = i * 3;\n    print(j)\n'

! シェルコマンド等の実行

IPython
In [33]: !vim tmp.py

!lessなども、ちょっと覗きたい時に便利

感想

IPython notebook(現Jupyter notebook)は、かなり便利だけれど、さっとIPythonだけを立ち上げてゴニョゴニョしたい時が結構ある。

簡単にでも一度整理できてよかった。

(2022/07/01追記)
グラフをインタラクティブに確認しながら調整したいときは、plt.ion()が有効。

参考文献

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?