擅长:python、mysql、java
<p>使用<code>get_ipython()</code>获取对当前<a href="http://ipython.org/ipython-doc/dev/api/generated/IPython.core.interactiveshell.html" rel="nofollow noreferrer">InteractiveShell</a>的引用,然后调用<code>magic()</code>方法:</p>
<pre><code>In [1]: ipy = get_ipython()
In [2]: ipy.magic("run foo.py")
ERROR: File `u'foo.py'` not found.
</code></pre>
<p><strong>编辑</strong>参见<a href="https://stackoverflow.com/a/14411126/71522">minrk's answer</a>-这是一种更好的方法。</p>