Valid Python Code?

Frederic LAURENT frederic.laurent at
Thu Feb 17 03:04:22 EST 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


More information about the Python-list mailing list