是的,我在該行
print g["WF00"+str(i)].value(1,1)
得到的錯誤是
KeyError: 'WF001'
進行打印g.keys()時,我得到這個名單。正如我提到的,我不是程序員,而這些對我來說不算什麼。
['gt', 'help', 'SQRT2', 'random', 'imul', 'ge', 'TechlogMath', 'sqrt', 'acosh', '__package__', 'getDatasetZoneIndiceTop', 'ParameterProxy', 'LOG2E', 'le', 'getitem', 'Histogram', 'frexp', 'platform', 'add', 'delslice', 'degrees', 'outputTL', 'division', 'rshift', 'factorial', '__file__', 'findNearestIndexBefore', 'ceil', 'unitValueListConvert', 'iconcat', 'isCallable', 'mod', 'isub', '__group__', 'd', 'printError', 'radians', 'sin', 'setitem', 'SQRTH', 'fmod', 'output', 'div', 'LOOP', 'findNearestIndexUnsortedUncleanData', 'findNearestIndex', 'boxCox', 'not_', 'cosh', 'hypot', 'UF001', 'parameterDict', 'E', 'isMappingType', 'eq', 'asin', 'isnan', 'xor', 'sub', 'HistoryItem', 'MissingValue', 'sequenceIncludes', 'getslice', 'truth', 'LogView', 'indexOf', 'abs', 'exit', 'idiv', 'mul', 'PI', 'UN001', 'irepeat', 'is_', 'modf', '__builtins__', 'copysign', 'ws', 'sinh', 'ipow', 'LOOP_INV', 'trunc', 'or_', 'cos', 'CrossPlot', 'g', 'outputSHerr', 'CacheVarData', 'itruediv', 'ProgressBar', 'erfc', 'w', 'pow10', 'acos', 'LOOP_ARRAY_MVTEST', 'os', 'gamma', 'delitem', 'iand', 'countOf', 'pythonEditor', 'pow', 'fsum', 'pos', 'TechlogRealTime', 'ldexp', '__suffix__', 'and_', 'lshift', '__name__', 'ixor', '__prefix__', 'TechlogPlot', 'plot', 'LOOP_ARRAY', 'winId', 'log', 'invert', 'contains', 'lt', 'isSequenceType', 'irshift', 'Variable', 'PrintErrorLimit', 'limitValue', 'pi', 'log10', 'outputSH', 'exp10', 'asinh', 'expm1', 'LN2', 'iif', 'PIO2', 'LOOP_MVTEST', 'PIO4', 'TechlogStat', 'tanh', 'TechlogDatabase', '__doc__', 'lgamma', 'erf', 'getDatasetZoneIndiceBottom', 'isNumberType', 'ilshift', 'log1p', 'ifloordiv', 'almostEqual', 'outputLogger', 'inv', 'printErrorCount', 'LN10', 'tan', 'TechlogPlatform', 'iadd', 'LOOP_INV_ARRAY', 'fabs', 'floor', 'Parameter', 'atanh', 'ne', 'setslice', 'outputTLerr', 'attrgetter', 'ExitExpectedException', 'methodcaller', 'truediv', 'applyMode', '__techlog_database', 'LOOP_INV_MVTEST', 'boxCoxInv', 'unitValueConvert', 'stat', 'repeat', 'Serr', 'atan', 'index', 'LOG10E', 'db', 'ior', 'sys', 'printTest', 'isinf', 'Sout', 'is_not', 'concat', 'LOOP_INV_ARRAY_MVTEST', 'e', 'i', 'imod', 'atan2', 'floordiv', 'exp', 'neg', 'Array', 'itemgetter']
我應該如何實現你的例子:?
for key in g.keys():
g[key].value(1,1)
「我在這個論壇中發現如何使用global()函數迭代變量。」哪裏?因爲我*真的*要去那裏,並低估誰提出這個建議。 *不*使用'globals()'。將'WF'變量放入一個列表並遍歷列表。除「不起作用」之外*不*意指*任何*!如果它在* full *回溯後引發異常,如果它給出的結果是您不希望發佈實際結果*和*您期望的結果! – Bakuriu
@Bakuriu:在精神上我和你有200%的差距,但OP至少有可能將其數據結構注入到嵌入式Python全局變量()中。如果'g [「WF00」+ str(1)]'有效,那麼這可能是發生了什麼,儘管OP的更新似乎排除了這一點。第一步仍然可能是將它們從'globals()'中提取出來,然後將它們放入一個列表或更有用的字典中。 – DSM