很多人都坚信不应该有IPython语法的脚本,但是如果你有足够的好奇心(就像我一样),并且正在寻找一些有趣的方法来混合python和shell脚本,那么您应该看看我的wrapper program on github
示例用例:$ cat > example.ipy
rehashx
a = !ls -l | tail -n 3
print a.fields(0)
b = 'foo'
echo bar ${b}
^{pr2}$
事实证明,IPython内核还支持上述脚本的一个(几乎不起作用)版本:In [2]: IPython.core.interactiveshell.InteractiveShell.safe_execfile_ipy?
Type: instancemethod
Base Class:
String Form:
Namespace: Interactive
File: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/core/interactiveshell.py
Definition: IPython.core.interactiveshell.InteractiveShell.safe_execfile_ipy(self, fname)
Docstring:
Like safe_execfile, but for .ipy files with IPython syntax.
Parameters
----------
fname : str
The name of the file to execute. The filename must have a
.ipy extension.