[Tutor] os.environ weirdness

alan.gauld@bt.com alan.gauld@bt.com
Tue Dec 10 06:19:00 2002


> Another phenomenon I haven't made sense of:
> 
>  >>> for i in os.environ:
>     print i

Yeah, I can't make sense of the 'in' operation on dictionaries either.... 
is it the key that's in or the value? Wierd....

Much better to be explicit:

for k in os.environ.keys()
   print os.environ[k]

> I realize that os.environ is not a builtin dictionary, but 
> some sort of subclassed dictionary, but these commands work:
> 
> os.environ.keys()
> os.environ.items()

Yep, thats why i prefer to use them.

> doesn't the "in" statement just resolve to one of those functions?

Dunno, like I said the whole concept of 'in' applying to a 
dictionary confuses the heck out of me... ;-)

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld