Is there a way to use TPython::Eval
for a variable with local scope or is it limited to globals? Details follow.
For example, if I declare a variable inside a function, TPython
does not know what it is:
In [1]: import ROOT
In [2]: def afunc():
...: valdict = {}
...: ROOT.gInterpreter.ProcessLine('TPython::Eval("valdict")')
...:
In [3]: afunc()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<string> in <module>()
NameError: name 'valdict' is not defined
(const TPyReturn) @0x7fd956c0a780
If, however, I make that variable global
, TPython
can find it just fine:
In [5]: def afunc():
...: global valdict
...: valdict = {}
...: ROOT.gInterpreter.ProcessLine('TPython::Eval("valdict")')
...:
In [6]: afunc()
(const TPyReturn) @0x7fd956bbc3d0
ROOT Version: 6.19/01
Platform: macOS Mojave
Compiler: Not Provided