当我在iPython中使用%edit
时,它总是将代码输出到终端。
示例:
In [3]: %edit
IPython will make a temporary file named: /tmp/ipython_edit_w6lcmt6t/ipython_edit_39zq1bwq.py
Editing... done. Executing edited code...
Out[3]: "# This is test code that I don't want to see unless we have errors.\n\ndef test():\n print('This is a test.')\n"
这在示例代码中没有问题,但是如果我粘贴大型脚本,那么很难看是否有任何错误
In [4]: %edit
IPython will make a temporary file named: /tmp/ipython_edit_hfkfj_de/ipython_edit_utpsoo79.py
Editing... done. Executing edited code...
File "/tmp/ipython_edit_hfkfj_de/ipython_edit_utpsoo79.py", line 1
def test()
^
SyntaxError: invalid syntax
Out[4]: "def test()\n print('testing')\n"
如果Out[4]
比屏幕长,那么我将不得不滚动(有时很多)才能找到错误。
是否有办法禁止%edit
的输出?
注意:我意识到我可以做到
_ = %edit
但是有更好的方法吗?