Python: How to load a module twice?

后端 未结 3 403
一生所求
一生所求 2020-12-10 06:39

Is there a way to load a module twice in the same python session?
To fill this question with an example: Here is a module:

Mod.py

x = 0
         


        
3条回答
  •  执笔经年
    2020-12-10 06:54

    You could use the __import__ function.

    module1 = __import__("module")
    module2 = __import__("module")
    

    Edit: As it turns out, this does not import two separate versions of the module, instead module1 and module2 will point to the same object, as pointed out by Sven.

提交回复
热议问题