This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.environ.get returns incorrect data
Type: Stage: resolved
Components: Extension Modules Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: dbrandow, loewis
Priority: normal Keywords:

Created on 2010-04-08 21:37 by dbrandow, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg102646 - (view) Author: Dan Brandow (dbrandow) Date: 2010-04-08 21:37
I have a Windows 7 64 bit machine, which means it has a few different environment variables concerning the program files location:
PROGRAMFILES=C:\Program Files (x86)
ProgramFiles(x86)=C:\Program Files (x86)

Note that both env variables have "(x86)" at the end.

When I do an os.environ.get I get the following results:

Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit (AMD64)] on win32
>>> import os
>>> print os.environ.get('ProgramFiles(x86)')
C:\Program Files (x86)
>>> print os.environ.get('PROGRAMFILES')
C:\Program Files
>>> print os.environ.get('ProgramFiles')
C:\Program Files
>>>

Note the missing "(x86)" on the last two test cases.

I tried it on the 64-bit version of 2.5.4 as well:

Python 2.5.4 (r254:67916, Dec 23 2008, 15:19:34) [MSC v.1400 64 bit (AMD64)] on win32
>>> import os
>>> print os.environ.get('ProgramFiles(x86)')
C:\Program Files (x86)
>>> print os.environ.get('PROGRAMFILES')
C:\Program Files
>>> print os.environ.get('ProgramFiles')
C:\Program Files
>>>

Same result.  So I tried the 32-bit version of 2.5.4:

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32
>>> import os
>>> print os.environ.get('ProgramFiles(x86)')
C:\Program Files (x86)
>>> print os.environ.get('PROGRAMFILES')
C:\Program Files (x86)
>>> print os.environ.get('ProgramFiles')
C:\Program Files (x86)
>>>

...which gave the correct strings...
msg102647 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-04-08 21:43
This is the correct result. The value of the environment variables depends on whether a 32-bit or a 64-bit process is looking at them, see

http://msdn.microsoft.com/en-us/library/aa384274%28VS.85%29.aspx
History
Date User Action Args
2022-04-11 14:56:59adminsetgithub: 52596
2010-04-08 21:43:57loewissetstatus: open -> closed

nosy: + loewis
messages: + msg102647

resolution: not a bug
stage: resolved
2010-04-08 21:37:21dbrandowcreate