Re: reloading sys

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Thu, 31 Mar 1994 13:34:47 -0500

In article <TNB2D.94Mar31131350@henson.cs.virginia.edu>,
Tommy Burnette <tnb2d@Virginia.Edu> wrote:
>
>Python 1.0.1 (Mar 5 1994)
>Copyright 1991-1994 Stichting Mathematisch Centrum, Amsterdam
>>>> import sys
>>>> sys.ack = 'foo'
>>>> print sys.ack
>foo
>>>> reload(sys)
>Traceback (innermost last):
> File "<stdin>", line 1
>ImportError: No module named sys
>>>>
>
>What is going on here?

--- From Python/import.c : ---

object *
reload_module(m)
object *m;
{
char *name;
if (m == NULL || !is_moduleobject(m)) {
err_setstr(TypeError, "reload() argument must be module");
return NULL;
}
name = getmodulename(m);
if (name == NULL)
return NULL;
/* XXX Ought to check for builtin modules -- can't reload these... */
return get_module(m, name, (object **)NULL);
}

--- and somewhere in function get_module(): ---

if (fp == NULL) {
sprintf(namebuf, "No module named %s", name);
err_setstr(ImportError, namebuf);
return NULL;
}

If it's documented in the source, does that make it a *feature* rather
than a *bug* ?

[ Tommy: What exactly caused the core dump you described to me the
other day? I tried what I thought you said, and on AIX Python, it
didn't crash. But, it also didn't do what you wanted - i.e. clear
and reinitialize sys. ( Also, I'm still not quite sure why you
want/need to do this. What specifically needs to be reset ? ) ]

- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics