简体   繁体   English

宏环境变量无法在python中访问

[英]macro environment variables not able to access in python

in perl, reference the environment variables with: 在perl中,请使用以下命令引用环境变量:

print "$ENV{NAGIOS_HOSTNAME}\n";

In bash, reference the environment variables with: 在bash中,使用以下命令引用环境变量:

echo $NAGIOS_HOSTNAME

i'm trying to access the environment variables using os.environ['NAGIOS_HOSTNAME'] 我正在尝试使用os.environ['NAGIOS_HOSTNAME']访问环境变量

Below is the error 下面是错误

host_nagio=os.environ['NAGIOS_HOSTGROUPNAME'] host_nagio = os.environ [ 'NAGIOS_HOSTGROUPNAME']

` Traceback (most recent call last):
  File "Read_nagios_parm.py", line 6, in <module>
    host_nagio= os.environ['NAGIOS_HOSTGROUPNAME']
  File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'NAGIOS_HOSTGROUPNAME'`

How can i access the marco environment variables of nagios using python. 我如何使用python访问nagios的marco环境变量。

This seems to be a simple error in which i need to export. 这似乎是我需要导出的简单错误。

From the documentation : 文档中

os.environ

A mapping object [...] 映射对象[...]

os.environ['NAGIOS_HOSTGROUPNAME']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM