on perhaps unloading modules?

Chris Angelico rosuav at gmail.com
Mon Aug 16 15:24:26 EDT 2021


On Tue, Aug 17, 2021 at 4:02 AM Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> The second best way would be to not use import_module, but to
> exec() the student's code. That way you don't create an entry in
> sys.modules and don't have to worry about somehow unloading the
> module.

I would agree with this. If you need to mess around with modules and
you don't want them to be cached, avoid the normal "import" mechanism,
and just exec yourself a module's worth of code.

ChrisA


More information about the Python-list mailing list