在IPython中如何执行每一行的命令

时间:2015-08-04 14:38:13

标签: python ipython

我想知道是否可以为每一行执行命令。

能够打开/关闭它会很棒。

我的申请是发送"续订"在调试期间命令GUI。 也有趣的是管道输入文件等等。

examlpe:

In [1]: h.Draw("E","","")
Out[1]: 1922L
In [2]: h1.Draw("E","","same")
Out[2]: 1234L
In [3]: rt.gPad.Modified();rt.gPad.Update()
In [4]: h2.Draw("E","","same")
Out[4]: 3214L
In [5]: rt.gPad.Modified();rt.gPad.Update()

转换为:

In [1]: startUpdating()
In [2]: h.Draw("E","","")
Out[2]: 1922L
In [3]: h1.Draw("E","","same")
Out[3]: 1234L
In [4]: h2.Draw("E","","same")
Out[4]: 3214L

2 个答案:

答案 0 :(得分:0)

不是很自动,但您可以定义自定义线魔法,以便更轻松地执行重置。

In [1]: from IPython.core.magic import register_line_magic

In [2]: @register_line_magic
   ...: def renew(line):
   ...:     rt.gPad.Modified()
   ...:     rt.gPad.Update()
   ...:

In [3]: startUpdating()
In [4]: h.Draw("E","","")
Out[4]: 1922L
In [5]: %renew
In [6]: h1.Draw("E","","same")
Out[6]: 1234L
In [7]: %renew
In [8]: h2.Draw("E","","same")
Out[8]: 3214L

答案 1 :(得分:0)

现在我正在包装Draw方法

def ReDraw(self,*args, **kwargs):
      self.Draw(*args, **kwargs)
      rt.gPad.Modified()
      rt.gPad.Update()

rt.TTree.ReDraw = ReDraw
h.ReDraw("E","","")

它不是所要求的,我希望有一个特定于IPython的方式