Python 在 64 位 vista 上获取 os.environ[“ProgramFiles"] 的错误值 [英] Python get wrong value for os.environ["ProgramFiles"] on 64bit vista

查看:31
本文介绍了Python 在 64 位 vista 上获取 os.environ[“ProgramFiles"] 的错误值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Vista64 机器上的 Python 2.4.3.

Python 2.4.3 on a Vista64 machine.

环境中有以下2个变量:

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"?

推荐答案

来自 维基百科页面:

%ProgramFiles%

%ProgramFiles%

该变量指向 Program Files 目录,该目录存储了 Windows 和其他所有已安装的程序.英语语言系统上的默认值是 C:Program Files.在 64 位版本的 Windows(XP、2003、Vista)中,还有 %ProgramFiles(x86)% 默认为 C:Program Files (x86) 和 %ProgramW6432% 默认为 C:Program Files.%ProgramFiles% 本身取决于请求环境变量的进程本身是 32 位还是 64 位(这是由 Windows-on-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 在 64 位 vista 上获取 os.environ[“ProgramFiles"] 的错误值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆