开发者

os.environ does not contain HOST variable

开发者 https://www.devze.com 2023-02-20 14:27 出处:网络
What could be the cause that os.environ does not contain the HOST environment variable under Linux, except I set it explicitly for the interpreter environment?

What could be the cause that os.environ does not contain the HOST environment variable under Linux, except I set it explicitly for the interpreter environment?

> echo $HOST; python -c 'import os; print "HOST" in os.environ'
bbox
False
> echo $HOST; HOST=$HOST python -c 'import os; print "HOST" in os.environ'
bbox
T开发者_如何学Gorue

EDIT: Thanks for the suggestion to export, however, why are most of the other variables available, like USER, PS1, LANG,... without explicitly exporting them?


This means that you've got a variable called HOST defined in your shell, but have not exported it.

Try this:

export HOST

Environment variables are not passed to child processes unless they have been exported this way.


Setting a variable in a shell does not make it available to subprocesses; you must export the variable as well.

$ export HOST
$ python ...
0

精彩评论

暂无评论...
验证码 换一张
取 消