Strange result on os.environ

holger krekel pyth at devel.trillke.net
Thu May 16 11:30:13 EDT 2002


Gonçalo Rodrigues wrote:
> Hi,
> 
> os.environ is supposed to be a mapping with keys the environment
> variables. Then what does it mean the following?
> 
> PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on
> win32.
> Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) -
> see 'Help/About PythonWin' for further copyright information.
> >>> import os
> >>> for key in os.environ:
> ... 	print key
> ... 	
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
>   File "C:\Python22\lib\os.py", line 387, in __getitem__
>     return self.data[key.upper()]
> AttributeError: 'int' object has no attribute 'upper'

environ isn't really a dictionary. try

    for key in os.environ.keys():
        print key

IIRC there recently was a patch for better behaviour
but don't count on it.

    holger





More information about the Python-list mailing list