Obtain Environment Variables

Function Description

The OPS allows you to obtain user-defined environment variables and system environment variables. User-defined environment variables are defined by users, and their names start with letters. System environment variables are defined by the system, and their names start with an underscore (_).

System environment variables are classified into public environment variables and event environment variables. During the registration phase, some environment variables related to events cannot be obtained (because the events have not occurred).

Command Prototype

opsObj.environment.get("envName")

Parameter Description

Table 1 describes the parameters supported by APIs for obtaining environment variables.
Table 1 Parameters supported by APIs for obtaining environment variables

Method

Description

opsObj

Specifies an OPS object. It is obtained through ops.ops() instantiation.

envName

Specifies the name of an environment variable. The value is a character string.

Description of Return Values

  • First return value: The value is a character string or None. The character string can be converted into a numeric environment variable through int().
  • Second return value: result description expressed in a character string.

Example

test.py

import ops

opsObj = ops.ops()
value, result = _opsObj.environment.get("_sysname")
print("result is ", result, " and sysname is ", value)

After the script is executed, the environment variables and device names are displayed.

Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
< Previous topic Next topic >