Get 2 isolated instances of a python module

前端 未结 5 997
逝去的感伤
逝去的感伤 2021-02-05 14:13

I am interacting with a python 2.x API written in a non-OO way, it uses module-global scope for some internal state driven stuff. It\'s needed in a context where it\'s no longer

5条回答
  •  -上瘾入骨i
    2021-02-05 14:51

    You can try by fooling sys.modules

    import badmodule as badmod1
    
    import sys
    del sys.modules['badmodule']
    
    import badmodule as badmod2
    

    If this works or not of course depends on what the bad module is doing...

提交回复
热议问题