[Python-checkins] python/dist/src/Lib getopt.py,1.21,1.22

Guido van Rossum guido@python.org
Sun, 28 Jul 2002 17:57:47 -0400


> >> Use os.environ.get() in stead of os.getenv() (which is 
> >> platform-dependent).
> >
> > Really?  That wasn't intended!  What are the differences?
> 
> The manual states that os.getenv() exists on Posix and Windows. 
> For os.environ no such statement is made. And indeed the mac 
> module has os.environ (even though the contents are rather 
> boring) and no os.getenv().

Hm.  That sounds like a bug.  There's code in os.py like this:

try:
    putenv
except NameError:
    pass
else:
    ...Here os.environ is redefined so changes are propagated...

    def getenv(key, default=None):
        return environ.get(key, default)
    __all__.append("getenv")

If this doesn't define getenv for you, it must mean you don't have
putenv?

It looks like the definition of getenv (which could be simplified to
"getenv = environ.get" BTW) ought to be outside the try/except/else
block.

--Guido van Rossum (home page: http://www.python.org/~guido/)