surprising behaviour of os.environ.clear

Joe P. Cool joe.p.cool at googlemail.com
Sat Jun 28 18:53:24 CEST 2008


On 28 Jun., 08:54, s0s... at gmail.com wrote:
> For one thing, the expression 'os.environ.keys' will yield a method
> object (not a list, as you're probably expecting), but iterating over
> a method as you did should produce an exception. If you want to get
> the list of environment vars, you have to call the method, like
> 'os.environ.keys()'.

You are right but it's just a typo in this message, sorry. My real
code is correct.

> Also, aren't changes to environment vars supposed to be visible to
> child processes anyway?

Yes. Both the clear method and the del method change os.environ.
os.environ IS the environment in a python program.


> Which one are you suggesting that behaves the
> wrong way, 'os.environ.clear()' or 'del os.environ[key]'?

The former. If a key is not in os.environ, it shouldn't exist for
child
processes.



More information about the Python-list mailing list