os.environ doesn't show all environmental variables in Jupyter notebook

时间:2016-08-31 18:26:39

标签: python environment-variables

I am finding that the following code prints out my expected environmental variable when I execute the script in a shell:

import os
print(os.environ['STUFF'])

However, when I run this same code in Jupyter Notebook, I get a key error. I have tried restarting the Jupyter server. What else should I do?

1 个答案:

答案 0 :(得分:0)

You can query all the dictionary keys to confirm the one you have is not there.

import os
print(os.environ.keys())

Or better you can test for the presence of the specific key.

print(os.environ.has_key('STUFF'))