How to change a Python module name?

后端 未结 7 689
暗喜
暗喜 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:35

    Where would you like to have this __module__ variable, so your original script knows what to import? Modules are recognized by file names and looked in paths defined in sys.path variable.

    So, you have to rename the file, then remove the oldname.pyc, just to make sure everything works right.

提交回复
热议问题