如果我声明一个环境变量,如:
$ export simple_variable="Test"
$ echo $simple_variable
Test
我可以使用以下命令在python中检索它:
>>> import os
>>> var = os.environ['simple_variable']
>>> print(var)
'Test'
但是,如果我声明一个数组环境变量,如:
$ export array_variable=(one two three)
$ echo ${array_variable[*]}
one two three
相同的python scrit将失败:
>>> import os
>>> os.environ['array_variable']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/os.py", line 725, in __getitem__
raise KeyError(key) from None
KeyError: 'array_variable'
为什么呢?如何从我的python脚本中检索此数组环境变量?