Skip to main content

Timeline for answer to How do I override a Python import? by Ron

Current License: CC BY-SA 2.5

Post Revisions

8 events
when toggle format what by license comment
Jul 3, 2025 at 5:26 comment added Karl Knechtel @DanielDonnelly The same way; nothing relevant changed in 3.x. Note that "the second import Mod_1 *rebinds the name Mod_1; without it, the new module is still "imported" and still cached in sys.modules, but Mod_1 still refers to the old module. Another way to rebind the name, of course, is with ordinary assignment: Mod_1 = sys.modules['Mod_1'] = __import__('Mod_2').
May 1, 2019 at 3:28 comment added TotoposAndPicoDeGallo How do you do it for Python 3.x?
Jul 13, 2017 at 13:07 comment added Abhijeet @Ron , I suppose this is only applicable to Python 2.x version.
Oct 26, 2015 at 0:14 comment added jwg @EvanPlaice the important thing is that you CAN do the second import Mod_1. Doing it doesn't reload or refresh the real module - it has been permanently replaced by Mod_2.
Jun 20, 2010 at 6:58 comment added Evan Plaice Thank you so much, this is almost identical to my implementation but it helped me get it right with an actual useful working example. Note: the second 'import Mod_1' is redundant because the line before it already takes care of that.
Jun 20, 2010 at 6:29 vote accept Evan Plaice
Jun 20, 2010 at 6:29 history bounty awarded Evan Plaice
Jun 19, 2010 at 6:49 history answered Ron CC BY-SA 2.5