在 CLion 中,是否可以“评估并记录”多个变量或在断点处创建字符串表达式?我尝试的简单语法(例如 printf)不起作用。
例如,如果我想在控制台中的断点处显示变量“a”和“b”的值,我应该在“断点”对话框的“评估和记录”文本框中输入什么内容?请注意,“a”和“b”可以是不同的类型。
谢谢! - 亚当
我正在尝试对 ipython notebook 中的 ROOT 文件进行一些操作(这里的 ROOT 是 CERN 的 ROOT 数据分析程序,带有 python 界面)。ROOT 令人讨厌的功能之一是它经常将输出直接发送到 stdout,而不是将这样的输出作为字符串返回。为了让这个输出作为结果出现在 ipython notebook 中,我写了一点cell_magic:
这是我的小细胞魔法代码
import tempfile
import ROOT
from IPython.core.magic import register_cell_magic
@register_cell_magic
def rootprint(line, cell):
"""Capture Root stdout output and print in ipython notebook."""
with tempfile.NamedTemporaryFile() as tmpFile:
ROOT.gSystem.RedirectOutput(tmpFile.name, "w")
exec cell
ROOT.gROOT.ProcessLine("gSystem->RedirectOutput(0);")
print tmpFile.read()
Run Code Online (Sandbox Code Playgroud)
如果我将此代码放入 ipython 笔记本单元并执行它,那么这很好用。例如,
In [53]: f = ROOT.TFile('myRootFile.root') # Load the Root file
In [54]: %%rootprint …Run Code Online (Sandbox Code Playgroud)