[Python-Dev] when is path==NULL?

Guido van Rossum guido at python.org
Tue Sep 30 16:27:53 CEST 2008

On Tue, Sep 30, 2008 at 5:48 AM, Christian Heimes <lists at cheimes.de> wrote:
> Ulrich Eckhardt wrote:
>> Hi!
>> I'm looking at trunk/Python/sysmodule.c, function PySys_SetArgv(). In that
>> function, there is code like this:
>>  PyObject* path = PySys_GetObject("path");
>>  ...
>>  if (path != NULL) {
>>    ...
>>  }
>> My intuition says that if path==NULL, something is very wrong. At least I
>> would expect to get 'None', but never NULL, except when out of memory. So,
>> for the case that path==NULL', I would simply invoke Py_FatalError("no mem
>> for sys.path"), similarly to the other call there.
> PySys_GetObject may return NULL after the user has removed sys.path with
> delattr(sys, 'path'). There are valid applications for removing sys.path.

Or before sys.path is initialized using PySys_SetPath(). Trust me,
this code is as it should be.

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

More information about the Python-Dev mailing list