Strange result on os.environ
Gonçalo Rodrigues
op73418 at mail.telepac.pt
Thu May 16 13:00:12 EDT 2002
On Thu, 16 May 2002 17:30:13 +0200, holger krekel
<pyth at devel.trillke.net> wrote:
>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
Confusing I´ll say. It isn't really a dict so I can't use the >2.2 idiom
for key in dict:
<whatever>
but it has a .keys() method...
>
>IIRC there recently was a patch for better behaviour
>but don't count on it.
>
> holger
>
Thanx 4 the answer,
Al the best,
Gonçalo Rodrigues
More information about the Python-list
mailing list