IPythonと正規表現のデモ - Engineer as a Lifestyle @tenkomaを使ってごにょごにょしてましたが,idleより軽すぎて気持ちがいいですね.In[num]で入力文字列がOut[num]で出力が参照できますが,Inは特殊なlistインスタンス(文字列が入っている)でOutはただのdictインスタンスのようです.In?と入れると説明がでてきます.
In [15]: In? Type: InputList Base Class: <class 'IPython.iplib.InputList'> String Form: ['\n', 'In\n', 'In\n', '"hoge"\n', 'In\n', '#?In\n', '#?Out\n', '#?3\n', 'hoge = 3\n', '#?hoge\n', "str = 'hoge'\n", '#?str\n', 'import re\n', ' #?re\n', '#?In\n', '#?In\n'] Namespace: Interactive Length: 16 Docstring: Class to store user input. It's basically a list, but slices return a string instead of a list, thus allowing things like (assuming 'In' is an instance): exec In[4:7] or exec In[5:9] + In[14] + In[21:25]
というわけでInputlistをスライシングしたりインデクシングしてexecにかけるとそのときの命令文が実行できるっぽい.
ん?インデクシングの実行は理解できるとしてこれって普通のリストでもできるんか?と思って試したが無理だった.
ソースを読むと
def __getslice__(self,i,j): return ''.join(list.__getslice__(self,i,j))
スライシングするとその要素文字列をくっつけたものが返ってくるので実行されるというわけか.
参考:http://python.matrix.jp/modules/ipython.html