在ipython中,我已经在配置文件中启用了自动重载。通常,这会获取我代码中的所有更改,并且ipython将执行新编译的版本。但是,如果代码中存在语法错误,我会得到旧版本。有时这种情况并不明显,这非常令人困惑。自动重载期间出现错误时,如何防止代码重新运行?另外,如何使这种错误更明显呢?
示例:考虑此脚本
from __future__ import print_function
def do():
for i in xrange(50):
print('lines that obscure the view')
print()
print('Old version')
Run Code Online (Sandbox Code Playgroud)
我用
In [1]: import junk
In [2]: junk.do()
Run Code Online (Sandbox Code Playgroud)
产生
...
lines that obscure the view
lines that obscure the view
Old version
Run Code Online (Sandbox Code Playgroud)
现在将其更改为:
from __future__ import print_function
def do():
for i in xrange(50):
print('lines that obscure the view')
print()
# print('Old version')
a = 3 *
print('New version')
Run Code Online (Sandbox Code Playgroud)
重新运行代码后,自动重载将生成语法错误,然后ipython将快速生成将错误滚动到屏幕之外的输出。
...
lines that obscure the view
lines that obscure the view
Old version
Run Code Online (Sandbox Code Playgroud)
我正在使用python 2.7.12和ipython 5.1.0。
| 归档时间: |
|
| 查看次数: |
98 次 |
| 最近记录: |