Valid Python Code?

Frederic LAURENT frederic.laurent at sxb.bsf.alcatel.fr
Thu Feb 17 09:04:22 CET 2000


Anders M Eriksson wrote:

> Hello!
>
> I'm just wondering is this a valid Python code snippet?
>
> import os
> for k,v in os.environ.values():
>     print k,v
>
> I can't get it to work!?

os.environ is dictionnary so you can access to the keys
by the keys() method, and to the values by the values() method.

The values() method returns a list of values, so the k,v expression
doesn't match.

you can adapt your code like the following

for k in os.environ.keys():
    v = os.environ[k]
    print k,v


Fred






More information about the Python-list mailing list