on perhaps unloading modules?

Hope Rouselle hrouselle at jevedi.com
Thu Aug 19 13:32:57 EDT 2021


Chris Angelico <rosuav at gmail.com> writes:

> 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.

Sounds like a plan.  Busy, haven't been able to try it out.  But I will.
Soon.  Thank you!


More information about the Python-list mailing list