擅长:python、mysql、java
<p>当文档没有指定行为并且您想自己发现答案时,可以查看源代码。在这种情况下,您可以通过<a href="http://svn.python.org/" rel="noreferrer">http://svn.python.org/</a>在线获取<code>os.py</code>的源代码:</p>
<ul>
<li><a href="http://svn.python.org/projects/python/trunk/Lib/os.py" rel="noreferrer">^{<cd1>} (Python trunk)</a>。在</li>
<li><a href="http://svn.python.org/projects/python/branches/release27-maint/Lib/os.py" rel="noreferrer">^{<cd1>} (Python 2.7)</a>。在</li>
</ul>
<p>代码中的注释说:</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>在Windows上,您还可以看到实现中的差异-<code>key.upper()</code>代替了<code>key</code>:</p>
<p>Linux系统:</p>
^{pr2}$
<p>窗口:</p>
<pre><code>def __setitem__(self, key, item):
putenv(key, item)
self.data[key.upper()] = item
</code></pre>