I need to access the process’ environment block in a platform-independent manner.
The python os module docs don’t specify anything about case-sensitivity of the os.environ / os.getenv. Experimenting on my ubuntu and win7 dev box’s, I see that os.environ is case sensitive on linux but not on windows (This mirrors the behavior of set on both platforms)
Since dict’s are obviously case-senstive for string keys, it appears that the value returned by os.environ is only duck-typed as a dict…
Question:
Where/How should I be able to find the definitive answer on this behavior? I would rather have a real answer than just empirically determine it 🙂
Alternatively, is os.getenv(…) a better api to use? why?
Thanks!
When the documentation doesn’t specify the behaviour and you want to discover the answer yourself, you can look in the source code. In this case you can get the source code for
os.pyonline at http://svn.python.org/:os.py(Python trunk).os.py(Python 2.7).The comments in the code say:
You can also see a difference in the implementations –
key.upper()is used instead ofkeyon Windows:Linux:
Windows: