在ipython中,有时我想输入多行代码,这样就可以回顾历史并再次调用它。问题是它会在按回车键后立即执行。在按return键之前,我正在使用\,但需要删除它。
发布于 2020-05-30 04:07:26
我的想法是创建一个空的with,这样我的语句就可以放在一个块中。是的,但是什么是空的with?
不是吧!下面是我的建议:
#!/usr/bin/python
# noop to use in with statement, so that ipython does not execute uppon pressing enter.
class noop(object):
def __enter__(self):
pass
def __exit__(self, exc_type, exc_val, exc_tb):
pass您可以将其放在~/.ipython/profile_default/startup/noop.py中,以便直接使用,如下所示:
with noop():
x=None
print(x)如果有两种输入模式就太好了。将模式更改为空行,并使提示符反映此状态
https://stackoverflow.com/questions/62093877
复制相似问题