Python中获取os.environ错误值[" PROGRAMFILES"]在64位Vista的 [英] Python get wrong value for os.environ["ProgramFiles"] on 64bit vista
问题描述
一Vista64上机器上的Python 2.4.3。
Python 2.4.3 on a Vista64 machine.
以下两个变量在环境中:
The following 2 variables are in the environment:
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
但是,当我运行下面的
But when I run the following
import os
print os.environ["ProgramFiles"]
print os.environ["ProgramFiles(x86)"]
我得到:
C:\Program Files (x86)
C:\Program Files (x86)
任何想法如何,我可以得到PROGRAMFILES?
Any idea how can I get the correct value of "ProgramFiles"?
推荐答案
在<一个href="http://en.wikipedia.org/wiki/Environment%5Fvariable#Examples%5Ffrom%5FMicrosoft%5FWindows">Wikipedia页面:
的%ProgramFiles%
%ProgramFiles%
该变量指向Program Files目录下,它存储的Windows和其他的所有已安装的程序。在英文系统默认为C:\ Program Files文件。如果是Windows(XP,2003,Vista)的64位版本,还有的%ProgramFiles(x86)的%默认为C:\ Program Files文件(x86)的和%ProgramW6432%,默认为C:\ Program Files文件。该的%ProgramFiles%本身取决于请求环境变量的过程本身是否是32位或64位(这是由Windows上Windows的64位重定向造成的)。
This variable points to Program Files directory, which stores all the installed program of Windows and others. The default on English-language systems is C:\Program Files. In 64-bit editions of Windows (XP, 2003, Vista), there are also %ProgramFiles(x86)% which defaults to C:\Program Files (x86) and %ProgramW6432% which defaults to C:\Program Files. The %ProgramFiles% itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit (this is caused by Windows-on-Windows 64-bit redirection).
所以得到的只是C:\ Program Files文件,你显然要检查%ProgramW6432%
So to get just C:\Program Files, you apparently want to check %ProgramW6432%
.
这篇关于Python中获取os.environ错误值[&QUOT; PROGRAMFILES&QUOT;]在64位Vista的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!