Python 在 64 位 Vista 上获得 os.environ ["ProgramFiles"] 的错误值

标签 python windows 64-bit

Vista64 机器上的 Python 2.4.3。

环境中有以下2个变量:

ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)

但是当我运行以下命令时

import os
print os.environ["ProgramFiles"]
print os.environ["ProgramFiles(x86)"]

我得到:

C:\Program Files (x86)
C:\Program Files (x86)

知道如何获得“ProgramFiles”的正确值吗?

最佳答案

来自Wikipedia page :

%ProgramFiles%

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%

关于Python 在 64 位 Vista 上获得 os.environ ["ProgramFiles"] 的错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1283664/

相关文章:

c# - .NET 'Settings' 无法在 64 位上运行(InvalidOperationException)

python - pandas 中的数据争论

python - Django MEDIA_ROOT 指向网络驱动器

python 正则表达式,字典未插入mysql

c# - Windows - C#- Directory.Move

windows - 以编程方式在用户桌面上创建网络快捷方式

windows - 为 32 位 PCI 设备编写 Windows 64 位设备驱动程序

C#:根据平台访问 32 位/64 位 DLL

python - Pycharm:有没有办法保存断点状态并继续调试?

python - 当我认为不应该时,App Engine urlfetch 正在引发异常