Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Because Windows environment variables are case <em>insensitive</em>, but a Python dictionary is case sensitive. By uppercasing all entries, you ensure that you'll always be able to match entries.</p> <p>Quoting from the Python <a href="http://hg.python.org/cpython/file/2.7/Lib/os.py#l411" rel="nofollow"><code>os.py</code> source code</a>:</p> <pre><code>elif name in ('os2', 'nt'): # Where Env Var Names Must Be UPPERCASE # But we store them as upper case # ... else: # Where Env Var Names Can Be Mixed Case </code></pre> <p>Note that the <code>os.environ</code> object translates <em>all</em> access to uppercase, including searches:</p> <pre><code>def __setitem__(self, key, item): putenv(key, item) self.data[key.upper()] = item def __getitem__(self, key): return self.data[key.upper()] # ... def has_key(self, key): return key.upper() in self.data def __contains__(self, key): return key.upper() in self.data def get(self, key, failobj=None): return self.data.get(key.upper(), failobj) </code></pre> <p>This means that if a program fails to find <code>os.environ['windir']</code>, then the value <em>is not set</em>.</p> <p>If you <strong>have</strong> to have access to the original values, grab them from the <code>nt</code> module:</p> <pre><code>import nt nt.environ </code></pre> <p>That's the raw initial dictionary as passed in by the OS, unaltered:</p> <pre><code>&gt;&gt;&gt; import nt &gt;&gt;&gt; sorted(nt.environ.keys()) ['ALLUSERSPROFILE', 'APPDATA', 'COMPUTERNAME', 'ComSpec', 'CommonProgramFiles', 'CommonProgramFiles(x86)', 'CommonProgramW6432', 'FP_NO_HOST_CHECK', 'HOMEDRIVE', 'HOMEPATH', 'LOCALAPPDATA', 'LOGONSERVER', 'NUMBER_OF_PROCESSORS', 'OS', 'PATHEXT', 'PROCESSOR_ARCHITECTURE', 'PROCESSOR_IDENTIFIER', 'PROCESSOR_LEVEL', 'PROCESSOR_REVISION', 'PROMPT', 'PSModulePath', 'PUBLIC', 'Path', 'ProgramData', 'ProgramFiles', 'ProgramFiles(x86)', 'ProgramW6432', 'SESSIONNAME', 'SSH_AUTH_SOCK', 'SystemDrive', 'SystemRoot', 'TEMP', 'TMP', 'USERDNSDOMAIN', 'USERDOMAIN', 'USERNAME', 'USERPROFILE', 'windir', 'windows_tracing_flags', 'windows_tracing_logfile'] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload