IPythonでカレンダーをみたい。 そんなときは、適当なファイルに下記を書いて、そのファイル名を環境変数のPYTHONSTARTUPに指定すればOK。

import IPython.core.getipython, calendar, datetime
ip = IPython.core.getipython.get_ipython()
def cal_impl(self, args):
	s, t = args.split(), datetime.datetime.today()
	m, y = (s + [t.month])[0], (s[1:] + [t.year])[0]
	print(calendar.month(int(y), int(m)))
ip and ip.define_magic('cal', cal_impl)

IPythonで cal とすればカレンダーが表示される。cal 1なら1月、cal 1 2014なら2014年1月になる。


最近、打合せ資料や学会発表資料をIPython notebookで作っている。ipython notebookのprivate リポジトリがあって好きにインストールできるならば、ネットにつなげるだけで、資料を共有できて、実行もできる。