reloading module which has been imported to another module

后端 未结 6 1042
难免孤独
难免孤独 2021-01-01 19:32

Let\'s face it, the whole business of reloading python code after changing it is a mess. I figured out awhile back that calling import at the in

6条回答
  •  长发绾君心
    2021-01-01 19:44

    Don't forget that an import is really just assigning a name in a namespace. So, you could reassign that name after reloading:

    >>> reload(module2)
    >>> module1.class1 = module2.class1
    

    Now the class1 object inside module1 refers to the reloaded version from module2.

提交回复
热议问题