Restoring script variable
Subscription and execution phases
result1_value, result2_description = ops.context.retrieve(varName)
Parameter |
Description |
Value |
---|---|---|
varName |
Indicates a variable name. |
The value is specified in the saving script variable API. |
The result1_value and result2_description in the API prototype indicate return values.
The first value is None if the specified variable fails to be restored. If the variable is restored successfully, the first value is the specified variable.
The second return value is the failure cause when the first return value is None.
You can use this API in scripts to restore values of script variables in context. After the value is restored, the saved value is deleted.
The restoring script variable API and saving script variable API are used together to transmit script variables between contexts.
Read user input from a terminal, use the script variable input1 to save the user input, and then restore the value of the script variable input1.
value1, descri_str1 = ops.terminal.read(512, timeout=30, vty=None) value2, descri_str2 = ops.context.save("input1", value1) value3, descri_str3 = ops.context.retrieve("input1")