How to change a Python module name?

后端 未结 7 718
暗喜
暗喜 2021-01-02 23:56

Is it only possible if I rename the file? Or is there a __module__ variable to the file to define what\'s its name?

7条回答
  •  鱼传尺愫
    2021-01-03 00:39

    Every class has an __module__ property, although I believe changing this will not change the namespace of the Class.

    If it is possible, it would probably involve using setattr to insert the methods or class into the desired module, although you run the risk of making your code very confusing to your future peers.

    Your best bet is to rename the file.

提交回复
热议问题