Practice ยท 1 of 1
Module identity and once-only bodies
Implement class ReloadableModule demonstrating import-cache semantics:
1. install(name) creates a types.ModuleType(name), sets mod.exec_count = 0, registers it in sys.modules[name], and stores it on self.modules[name].
2. import_again(name) returns sys.modules[name] WITHOUT re-executing anything.
3. simulate_body_execution(name) increments that module's exec_count += 1 (simulating a module body run).
4. identity_stable(name) returns True when repeated import_again calls always return the SAME object.
Graded checks: identity is stable; exec_count only changes when simulate_body_execution is explicitly called โ mirroring real import-once semantics.
Difficulty: advanced
Press Submit to check your solution.
Back to lesson: Practice: Import System Practice