[issue1159] os.getenv() not updated after external module uses C putenv()
Robert Ancell
report at bugs.python.org
Fri Sep 14 02:20:26 CEST 2007
Robert Ancell added the comment:
draghuram, unfortunately while os.putenv() can be fixed to be
symmetrical any putenv call from a C module cannot, for example:
If you make an extension:
#include <stdlib.h>
PyObject *putenvC(PyObject *module, PyObject *args)
{
int result;
if (!PyArg_ParseTuple(args, ""))
return 0;
result = putenv("FOO=BAR");
return Py_BuildValue("i", result);
}
The following behaviour will occur:
$ python
>>> import putenv
>>> putenv.putenvC()
>>> assert(os.getenv('FOO') == None)
>>> assert(os.environ.get('FOO') == None)
This is because the os.environ dictionary will never be updated:
>From Lib/os.py:
def getenv(key, default=None):
"""Get an environment variable, return None if it doesn't exist.
The optional second argument can specify an alternate default."""
return environ.get(key, default)
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1159>
__________________________________
More information about the Python-bugs-list
mailing list