Strange result on os.environ

Steven Majewski sdm7g at Virginia.EDU
Thu May 16 14:43:30 EDT 2002


On Thu, 16 May 2002, Gonalo Rodrigues wrote:

> >environ isn't really a dictionary. try
> >
> >    for key in os.environ.keys():
> >        print key
>
> Confusing Ill 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...

Coercing os.environ to a dict will also work:

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

however this will not work:

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

although this will:

	for key in iter(dict(os.environ)): print key


-- Steve M.






More information about the Python-list mailing list