Re: import restrictions

Guido.van.Rossum@cwi.nl
Mon, 18 Oct 1993 08:57:09 +0100

> One problem I've been having is that once I have imported
> a file of definitions into a python session I can't seem
> to get rid of it. When I'm editing a script I'd like
> to have python going in another window, edit the script,
> re-import it into python, and test it. It seems, however,
> that even if I explicitly delete the script's module from
> my python session symbol table, the script file is not
> re-read/re-interpreted when I import it into the python
> session again.

This is intentional -- when you import a module, Python remembers that
it has imported it so that if you import it again (usually from
another module) it won't be parsed, compiled and initialize again.

For the situation you are having, however, you can use the reload()
built-in function, which forces reparsing etc. of the module. Note
that the syntax is
reload(expression)
where the expression must evaluate to a module object; i.e. you must
already have imported the module once. Note that reload() does not
recursively reload modules imported by the reloaded module; you will
have to do that yourself if it is necessary.

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>