Using this code, many keys are output, but I expected no output:
import os
for i in os.environ:
print i
This is the code from os.py:
try:
environ
except NameError:
environ = {}
Where does os.environ get its values from? Where is it initialized?
The
osmodule starts by importing all names from a platform-specific submodule (such as_ntor_posix) then does a little normalization. Clearly theenvironname (standing for the system environment) was defined by the platform-specific submodule (as it’s normally expected to be!!!), so theexceptclause inos.pydidn’t trigger andos.environis just the rich dictionary it’s normally supposed to be.