modifying os.environ

Quinn Dunkan quinn at
Wed Apr 12 16:22:44 EDT 2000

Is there any way to delete things from the environment in python?  A look at reveals that _Environ only overrides __setitem__ to putenv.  So how do
you *delete* environment values?  perl does it, and a look at the source
seems to indicate that it doodles with the C environ directly.  So perhaps
python needs a delenv _Environ can use or something, or implement os.environ
in C?

Or perhaps there's a better way to do the (common) thing I'm trying to do:
clean the environment to insure some minimum sane values.  I can't make a copy
of the environ and then pass to execve() since that doesn't help much for
popen and system.  I can set values to '', but that doesn't seem as safe as
just removing them entirely (IFS, LD_LIBRARY_PATH, etc.?)

More information about the Python-list mailing list