> Yes. We could either check for `unsetenv` (as your code did) or just
> accept the small performance impact. I just checked in the later for now.

We are both aware of the performance overhead of solution b) below
(double modification of os.environ and both calling "putenv" and
"unsetenv" in the general case). However, there is also a small
semantic difference.

a)
del os.environ[name]
if not hasattr(os, 'unsetenv') and hasattr(os, 'putenv'):
    os.putenv(name, '')

b)
os.environ[name] = ""
del os.environ[name]

Considering a platform that supports only "putenv" but not
"unsetenv" (like e.g. AIX).

Trying to unset an existing variable leads to the best possible result
using both a) and b). The variable is set to the empty string.

However, trying to unset a non-existing environment variable using a)
leads to an error (because the key does not exist). Using b) we end up
creating the previously non-existing variable in the environment and
setting it to the empty string.

Also, IMHO a) is cleaner and easier to read because the if-statement
tells exactly what it does, whereas the
  os.environ[name] = ""
indirectly accomplishes its goal by causing an automatic call to
"putenv" which is not obvious.

I would prefer the first one because "explicit is better than
implicit". :-)
http://www.python.org/dev/peps/pep-0020/

/Martin

-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyinstaller?hl=en.

Reply via email to