Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 425
helloB Avatar asked Aug 31 '16 18:08

helloB


1 Answers

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'))
like image 190
edi_allen Avatar answered Sep 27 '22 21:09

edi_allen