本文整理汇总了Python中MDSplus.Data.getTdiVar方法的典型用法代码示例。如果您正苦于以下问题:Python Data.getTdiVar方法的具体用法?Python Data.getTdiVar怎么用?Python Data.getTdiVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDSplus.Data
的用法示例。
在下文中一共展示了Data.getTdiVar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execPy
# 需要导入模块: from MDSplus import Data [as 别名]
# 或者: from MDSplus.Data import getTdiVar [as 别名]
def execPy(varname=None,traceback=False):
"""Get array of python commands from tdi public variable ___TDI___cmds
and execute them. The ___TDI___cmds variable should be either a scalar string
or a string array. If varname is defined
then set the tdi public variable ___TDI___answer to the value of the variable
with the name specified in varname. If varname is not defined
then set public variable ___TDI___answer to 1 if there is no exception. If there
is an exception then set public variable ___TDI___exception to be the
exception string.
"""
from MDSplus import Data as ___TDI___Data,makeData as ___TDI___makeData,String as ___TDI___String
try:
cmds=list()
for cmd in ___TDI___Data.getTdiVar('___TDI___cmds'):
cmds.append(str(cmd))
cmds="\n".join(cmds)
isglobal=False
try:
if int(___TDI___Data.getTdiVar('___TDI___global_ns'))==1:
isglobal=True
except:
pass
ans=1
if isglobal:
exec( cmds) in globals()
if varname is not None:
if varname in globals():
ans=globals()[varname]
else:
ans=None
else:
ns={}
exec( cmds) in ns
if varname is not None:
if varname in ns:
ans=ns[varname]
else:
ans=None
___TDI___makeData(ans).setTdiVar("___TDI___answer")
except Exception:
if traceback:
_tb.print_exc()
import sys
e=sys.exc_info()[1]
___TDI___String("Error: "+str(e)).setTdiVar("___TDI___exception")